Encapsulation enforces the separation between interface and implementation in a class via access specifiers. Encapsulation provides some advantages:
- A class that is encapsulated hides its implementation to the user of the class, thus the user need not know how the class works, they can regard the class as a type (like a built-in type) instead.
- User code cannot inadvertently corrupt the state of an encapsulated object.
- The implementation of an encapsulated class can change over time without requiring changes in user code.