|
|
|
The C++ member
access specifiers permits to the class author to decide which data members
and member functions are visible to whom.
|
|
This mechanism
provides several advantages and improves overall the quality of design:
|
|
If the class user,
who uses the class to create a more articulated design, can only see what is
in the public section, then he/she doesn’t have to care of the implementation
details that are not visible to him/her; this means that he/she can
concentrate on how to use the class, and how this reacts to invocations of
its member functions, instead of fiddling around with the internals of the
data type;
|
|
On the other hand,
for the class creator, this separation of interface and implementation is
also beneficial, since he/she can change the internal representation of the
storage of the data type, and even the algorithms embodied in the member
functions, as long as he/she doesn’t change the interface of the class (the
prototypes of the member functions); this ensures that such modifications
will not break existing codes written by users of the class.
|