Encapsulation and information hiding
Encapsulation is one of the basic principles of the OOP paradigm. It allows us to bundle it into one object both data and functionalities that operate on that data.
Using the methods exposed by the object to manipulate the data, we take advantage of the encapsulation principle ignoring its internal complexity and implementation details. In other words, encapsulation hides the internal details regarding how the object manipulates its data. This feature, called the information hiding principle, is often related to encapsulation, although it is a more general principle. By hiding internal details, we obtain at least two great benefits:
- We provide a simple way to use an object, hiding the internal complexity
- We decouple the internal implementation from the use of the object, simplifying change management
The information hiding principle enforces the design of objects to have at least two parts: a public part and a private one. Only the public...