Re: Using Get() and Set() instead of accessing the variable directly
On Tue, 20 Mar 2007 21:18:34 -0500, Joseph M. Newcomer
<newcomer@flounder.com> wrote:
If Set is not public, how do you set anything? Note that 'friend' is not a good
programming concept (Stroustrup added it to save a coworker from a problem and has said
that in retrospect he thought it was a bad idea).
I heard someone else say that years ago, and I'm curious what the origin
is. Here's a link to my reply (in 1997, no less, sheesh I remember some
useless things):
http://groups.google.com/group/microsoft.public.vc.language/msg/cceb96ee71a40aae
<q>
In "The Design and Evolution of C++", page 53, Stroustrup has this to
say about friendship declarations:
"It is an explicit and specific part of a class declaration.
Consequently, I have never been able to see the recurring assertions
that a friend declaration "violates encapsulation" as anything but a
combination of ignorance and confusion with non-C++ terminology."
</q>
Here's what Stroustrup says in his FAQ:
http://www.research.att.com/~bs/bs_faq2.html#friend
<q>
Does "friend" violate encapsulation?
No. It does not. "Friend" is an explicit mechanism for granting access,
just like membership. You cannot (in a standard conforming program) grant
yourself access to a class without modifying its source.
</q>
--
Doug Harrison
Visual C++ MVP