2.4.  Encapsulation

[ fromfile: encapsulation.xml id: encapsulation ]

Encapsulation is the first conceptual step in object-oriented programming. It involves

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.