How can I prevent other programmers from violating
encapsulation by seeing the private parts of my class?
Answer Posted / abalonesoft
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].
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Explain what are reserved words?
Synonymous with pointer array a) character array b) ragged array c) multiple array d) none
How can I send mail from within a c program?
What is the use of volatile?
What is the use of sizeof?
How main function is called in c?
How to delete a node from linked list w/o using collectons?
What is keyword with example?
Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above
What was noalias and what ever happened to it?
Write a simple code fragment that will check if a number is positive or negative.
What is the difference between functions getch() and getche()?
Explain what is operator promotion?
What is the significance of c program algorithms?
What is openmp in c?