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

Why does this code crash?

623


Write a program to print numbers from 1 to 100 without using loop in c?

644


What is the difference between void main and main in c?

627


What is strcmp in c?

603


What is meant by errors and debugging?

651






A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

626


How do I convert a string to all upper or lower case?

631


What is this pointer in c plus plus?

600


Explain how can I prevent another program from modifying part of a file that I am modifying?

644


How can I recover the file name given an open stream or file descriptor?

600


What are the 5 types of inheritance in c ++?

589


cavium networks written test pattern ..

3600


What is the difference between array and structure in c?

573


What is meant by preprocessor in c?

540


What is the data segment that is followed by c?

617