Do You Use Encapsulation?

Do You Use Encapsulation?

It gives you more freedom to change how your class works. It gives you the option to control the access to your class. You can check if what the user enters is valid (you don't want the user to enter a day with a value of 32). The main idea behind encapsulation is data hiding.

When should encapsulation be used?

Encapsulation is used to hide the values or state of a structured data object inside a class, preventing unauthorized parties' direct access to them.

Can you give an example for encapsulation?

School bag is one of the most real examples of Encapsulation. School bag can keep our books, pens, etc. Realtime Example 2: When you log into your email accounts such as Gmail, Yahoo Mail, or Rediff mail, there is a lot of internal processes taking place in the backend and you have no control over it.

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.