Skip to main content

What is Encapsulation?

Keeping an object's internal state private, and in general making a clear division between its public interface and its private internal state, is called encapsulation. The object's internal state is kept private, meaning that it can only be accessed by the object's own methods, not from other objects.

info

This is a useful feature because it enables the programmer to change the internal implementation of an object without having to find and update all the code that uses it: it creates a kind of firewall between this object and the rest of the system.