WritingaGoodProgram5.ObjectsandClasses inC++
Writing a Good Program 5. Objects and Classes in C++
ComputerProgrammingandBasicSoftwareEngineering5.ObjectsandClassesinC++5.3 ModularProgrammingwithC++
5.3 Modular Programming with C++ Computer Programming and Basic Software Engineering 5. Objects and Classes in C++
ComputerProgrammingandBasicSoftwareEngineering5.ObjectsandClassesinC++DoingBusinessbySellingClassesThe development of Object OrientedProgramming hasenabled a new business in software development.Peopledevelop different classes and sell to otherpeople.These classes often provide functions that are popularlyused in applications.>Forexample,the Java calculatorusedin some WebpagesPeople post the advertisement oftheir classes on the Web.Those who are interested in their classes can directlydownload it and perhaps pay by credit card
Computer Programming and Basic Software Engineering 5. Objects and Classes in C++ • The development of Object Oriented Programming has enabled a new business in software development. ➔ People develop different classes and sell to other people. • These classes often provide functions that are popularly used in applications. ➔ For example, the Java calculator used in some Web pages • People post the advertisement of their classes on the Web. Those who are interested in their classes can directly download it and perhaps pay by credit card. Doing Business by Selling Classes
ComputerProgrammingandBasicSoftwareEngineering5.ObjectsandClassesinC++Assumethat you have designed the following class cAT andwould like to sell it to a customer.#include<iostream>//forcoutusing namespace std;// declare the class objectclass Cat(public:void SetAge (int age) ;int GetAge();void Setweight (int weight)int GetWeight();private: int itsAge;You do not want to give him theint itsweight;source codes of the memberJ;functions since your customerint Cat::GetAge()tmay copy your codes.return itsAge;1They may modify it and re-sellvoid Cat::SetAge(int age)titsAge = ageiit to somebody else.1
Computer Programming and Basic Software Engineering 5. Objects and Classes in C++ • Assume that you have designed the following class CAT and would like to sell it to a customer. #include <iostream> // for cout using namespace std; class Cat // declare the class object { public: void SetAge (int age); int GetAge(); void SetWeight (int weight); int GetWeight(); private: int itsAge; int itsWeight; }; • You do not want to give him the source codes of the member functionssince your customer may copy your codes. • They may modify it and re-sell it to somebody else. int Cat::GetAge() { return itsAge; } void Cat::SetAge(int age) { itsAge = age; }
ComputerProgrammingandBasicSoftwareEnaineering5.ObjectsandClassesinC++If the customer has the source code,he may try to modifyitbyhimself..It may introduce a lot of hidden errors as he knows verylittleaboutyourprogram.The resulting program can be very difficult to debugConclusion: It is better to give your customer executablecodes such that they cannot read or modifyit.Problem l: A program withoutmain () cannot be built. Noexecutable codes can begeneratedwithoutmain ()Problem 2: If your customer only has the executable codes, howcan he know the way to use your class?
Computer Programming and Basic Software Engineering 5. Objects and Classes in C++ • If the customer has the source code, he may try to modify it by himself. • It may introduce a lot of hidden errors as he knows very little about your program . • The resulting program can be very difficult to debug. Conclusion: It is better to give your customer executable codes such that they cannot read or modify it. Problem 1: A program without main() cannot be built. No executable codes can be generated without main(). Problem 2: If your customer only has the executable codes, how can he know the way to use your class?