A class models a single entity -- one Person, one Car, one Book, one Library.
Classes are used to implement user-defined ADTs. These are classes whose external behavior is known to the class user, but whose internal implemenation is hidden.
But a data type is more than just data..... it also has a set of associated operations. Built-in types like int, float, char have opearations such as add, subtract and multiply. Since the details of these operations are hidden, we can consider the built-in data types to be "Abstract Data Types" (ADTs).
To accomplish this goal, we need a mechanism to hide the details of the class implementation from the class user.
Recall the initial DayOfYear class definition from the text.
Now consider this new improved (but not yet perfect) definition of the DayOfYear class. This definition is adapted from Display 6.4 of the text.
No item that follows the keyword private can be directly referenced by name in any code except the implementations of the class member functions. Attempting to do so results in a compiler error. The compiler enforces the hiding of class details through the use of the keyword private.
Items which follow the keyword public may be referenced in any code, just like members of a struct. Good programming practice, and a REQUIREMENT in this course is that all data members of a class must be declared private.
C++ implements encapsulation by allowing data members to be declared as private. A private datat member will only be accessible to functions that are members of that class and to functions and classes explicitly granted access permission by the class ("friends" -- more on this later).
Member functions that allow the class user to retreive the value of a private data member are known as accessor -- GetDay( ), GetMonthNumber().
Member functions that allow the class user to change the value of a private data member are known as mutators -- both Set( ) functions.
Other member functions generally provide support for the ADTs operations and are often referred to as services -- Input( ), Output( ) As we'll see next time, other special methods are also provided.