Re: Using Get() and Set() instead of accessing the variable directly

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



That is right!

I often use it that way. A data object may
expose himself to the control object that have
created em. It is up to data object to declare
the friendship relation with his creator...

Note that only methods and attributs of
the class where is the friendship declaration
are exposed (like public) to the creator. All
the parent class of this object stay unexposed!

So modifying a data object through a control
class is very powerfull...

jmarc...


"Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote in message
news:6cu203h9kcvef86qaaquaiar0qjr93b6e6@xxxxxxxxxx
On Tue, 20 Mar 2007 21:18:34 -0500, Joseph M. Newcomer
<newcomer@xxxxxxxxxxxx> 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


.