Thursday, April 9, 2015

How can I prevent other programmers from violating encapsulation by seeing the private parts of my class?

Not worth the effort — encapsulation is for code, not people.

It doesn’t violate encapsulation for a programmer to see the private and/or protected parts of your class, so long as they don’t write code that somehow depends on what they saw. In other words, encapsulation doesn’t prevent people from knowing about the inside of a class; it prevents the code they write from becoming dependent on the insides of the class. Your company doesn’t have to pay a “maintenance cost” to maintain the gray matter between your ears; but it does have to pay a maintenance cost to maintain the code that comes out of your finger tips. What you know as a person doesn’t increase maintenance cost, provided the code you write depends on the interface rather than the implementation.

Besides, this is rarely if ever a problem. I don’t know any programmers who have intentionally tried to access the private parts of a class. “My recommendation in such cases would be to change the programmer, not the code” [James Kanze; used with permission].


  1. Wow, What an article. Please post some related article as well very good information you have provide thank you for sharing.
    Our website

  2. Best Online Casinos of 2021 |
    Choegocasino Casino is an online casino site that is operated by choegocasino the Isle of 온카지노 Man Gaming Commission (LGA). The 제왕카지노 casino has over 4,000 games