February 18th, 2003, 03:09 AM
C++ newbie question
How can I prevent other programmers from violating encapsulation by seeing the private parts of my class?
February 18th, 2003, 04:24 AM
Are you Marshall Cline or James Kanze? Or is this just a coincidence?
Here is the link.
7.6] 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].
February 18th, 2003, 01:18 PM
February 18th, 2003, 10:33 PM
mathgirl im not sure where you found that i was actually asking for a friend of mine, who knows more about c++ then me at this point.i can see how you would think i plagerized or whatever but i assure you its just coincident.thanx for the link though, its very informative.again though sorry for the misunderstanding
Don\'t be a bitch! Use Slackware.
February 18th, 2003, 10:48 PM
Declare all your variables/functions/procedures in your class that you do not want to be visible as 'private', and only provide public functions to access/view the ones that you want to see using the 'public' key word.
There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.
(Merovingian - Matrix Reloaded)
February 18th, 2003, 11:20 PM
That's okay, hatebreed, I was just a little surprised when I saw that link. Also, it seemed, by the question you asked that you (or your friend) must already know about making class members private / public.....so, beyond that, I wasn't really sure where to go with that question.