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 allow 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 members, as well as the function definitions themselves, comprise the 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 ID of the particular instance. We could adopt the convention of calling such a data member m_ID in every class that needs one. Because class member names are not visible outside the class scope, there is no danger of ambiguity if a member name is also used somewhere else in the program.
Introduction to UML
|