Class Composition: A Shape "Has A" Fixed Point
Class Composition: A Shape "Has A" Fixed Point
In object-oriented programming:
• An object should protect its important data by
making it private
• An object should provide a public interface to
access the private data
Objects usually have some variables and functions that are only
used internally and should not be modified from outside the class
The interface is typically placed in a file that ends with .h. The
member functions are defined as:
ReturnType FunctionName(parameterList);
The implementation file typically ends with .cpp, .cc, or .C. The
member functions are defined as follows:
ReturnType ClassName::FunctionName(parameterList)
{ …… } Scoping operator
Abstract Data Type with a Class
class Time {
public:
Time(); // constructor
void setTime(int, int, int);
void printMilitary();
void printStandard();
private:
int hour;
int minute;
int second;
};
Declaration of Objects of Type
"Time"