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


Please Help Members By Posting Answers For Below Questions

Explain continue keyword in c

580


What are the rules for the identifier?

667


What is realloc in c?

581


How do I get a null pointer in my programs?

614


What is the benefit of using #define to declare a constant?

601






What is bash c?

553


What is the use of function overloading in C?

675


Is that possible to store 32768 in an int data type variable?

687


count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array

673


How are Structure passing and returning implemented by the complier?

710


What are the types of assignment statements?

626


How can you access memory located at a certain address?

663


Give basis knowledge of web designing ...

1569


what is the syallabus of computer science students in group- 1?

1836


What is C language ?

1524