Member visibility, as this function is often called, is not a security function. This is a convenience for the programmer, designed to limit interclass dependencies. When declaring a private person, you do not allow another code to access it directly. This has two advantages:
- if you find that the member variable is being processed the way you did not expect, the amount of code you should check is significantly less if the variable is private.
- you can change the internal operation of the class (everything that is declared private) without breaking the interface (everything is declared public)
Member visibility is probably the most important language function in the implementation of encapsulation, which is one of the basic principles of object-oriented programming.
source share