Roles in OOP
- Designer: thinks about how to solve problem
- Implementer: codes up member functions for
C++ classes. Must understand design at a detailed level.
- Client (a.k.a., "user"): Must understand
design at a high level. Uses methods provided by the class.
Abstract Data Types (ADT)
- Consists of data and functions.
- All operations on the data must use one of the functions
- Actual implementation should not make a difference to the client.
- Data hiding versus asking the client to playing nice.
New DayOfYear Definition
void Input( );
void Output( );
void Set( int newMonth, int newDay );
void Set( int newMonth );
int GetMonthNumber( );
int GetDay( );
public versus private
- Items in the private section can only be accessed by
member functions from the same class.
- The friend directive grants access to private data
members to non-member functions. Use this very rarely.
- Items in the public section can be accessed by any code.
- Usual recommendation is that all data members should
Because the data members are now private, public member functions
are written to provide indirect access to the data
for the class user.
- An accessor member function allows the class
client to retrieve the value of a private data member.
Mutator member functions allow the class client
to change the value of a private data member.
Member Function Guidelines
- Each member function should perform just one
task and do it well.
- Private functions may be written and called from the public
function to allow proper modularity.
- Class member functions should not perform input from or output to
the application user unless that is the function's explicit purpose.
- Although member functions have direct access to private data
members, your code should use accessors and mutators whenever
- Proper passing of parameters is vital for efficiency of
your program. Pass objects by reference, if possible.