Encapsulation (also called as data hiding) is a process where internal workings of system is hidden from the external world and public interfaces are provided to interact with the system. This makes the using of system easier for the users without needing the understanding of how system works.

Third party libraries that we use in our programs, we do not know about how they work, but we use them with the APIs (public interfaces) they have given.

There are several benefits of encapsulation:

  1. Hides complex internal details from the user.
  2. Provides consistent public interfaces which do not change irrespective if their internal working modifications.
  3. It allows us to maintain class invariants. In other words, it keeps the classes in valid state as we can only access it using public methods and can’t access the internal state. And so on…

References

  1. https://www.learncpp.com/cpp-tutorial/the-benefits-of-data-hiding-encapsulation/