Skip to main content

Encapsulation

Encapsulation enables us to wrap the data and functions into a single unit.

It binds the mechanism together as a protective shield that will prevent the classes or clients to access the internal data. In a real-life scenario, a car a power steering machine has a complex system that enables the car movement. This system is tightly coupled and works synchronously, but the complexity is entirely hidden from the car user. The drive can only use this system through an interface. Also, the internal functions are completely independent of on-another and thus do not affect other mechanisms unless needed.

Encapsulation enables:

  • The data binding within the system.
  • Protects it from the interference of the external system.
  • It helps in classes independently and prevents tight coupling.