[ fromfile: encapsulation.xml id: encapsulation ]
Encapsulation is the first conceptual step in object-oriented programming. It involves
Packaging data with the functions that can operate on that data in well-named classes.
Providing clearly named and well-documented public
functions that enable users of the class to do whatever needs to be done with objects of this class.
Hiding implementation details.
The set of public
function prototypes in a class is called its public interface.
The set of non-public
class members, together with the member function definitions, is called its implementation.
One immediate advantage of encapsulation is that it permits the programmer to use a consistent naming scheme for the members of classes.
For example, there are many different classes for which it might make sense to have a data member that contains the unit cost of the particular instance or, previously mentioned, a member function named toString()
.
Because class member names are not visible outside the class scope, you can safely adopt the convention of using the names m_unitCost
and toString()
in every class that needs such members.[26]
[26] The compiler will not be confused because it embeds the name of the class inside the complete name that it gives to each data member.
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |