On Thu, 29 May 2008 17:54:21 -0700, Mike Peretz <m_******@hotmail.com>
wrote:
I am wondering if anyone out there is trying to use friend with C#,
simular to the way C++ handles it.
No, no one ever asks this.
:)
Sorry, being facetious. Here:
http://groups.google.com/groups/sear...C%2B%2B+friend
Here's the most recent thread I know about
:
http://groups.google.com/group/micro...f4fe691b6a6b22
I wrote a blog about it and I wonder if someone can give me some
feedback.
http://mikeperetz.blogspot.com/2008/...uld-i-say.html
Well, one thing I'd say is that I think you're being a little hard on the
class in the non-static example, in calling it a "bully". The nested
class doesn't actually have access to the base class except through
itself. Inasmuch as the derived class "owns" anything it inherits in the
base class, it seems reasonable.
The big problem is that it doesn't really address the "friend" thing.
That is, a C++ friend could modify the member of _any_ instance of that
class, not just specific derived versions of it.
The static example provides a nice illustration of how dangerous protected
static members can be. Want to change it? Just inherit the class, and
you're in! No other class can control you. :)
If you read the specific thread I mentioned above, you'll see that it
doesn't really deal with "friend" per se either. However, it does discuss
a design pattern that IMHO may be a more appropriate approach to
"friend". I never really liked the idea of "friend" anyway, and I have
successfully written LOTS of code over the years without using it. There
always seem to be different, better approaches to managing relationships
between classes.
Some will argue (strike that...some _have_ argued) that I'm just naïve and
never wrote anything complex enough to warrant the use of "friend" and
that if only I had more experience, all would be clear to me. So feel
free to take what I say with a grain of salt (as you should anyway).
Suffice to say, I find those kinds of arguments ill-informed and somewhat
insulting. :)
Pete