static and protection

Regan Heath regan at netwin.co.nz
Wed Mar 1 16:52:29 PST 2006


On Wed, 01 Mar 2006 16:43:07 -0800, Kyle Furlong <kylefurlong at gmail.com>  
wrote:
> Jarrett Billingsley wrote:
>> "Hasan Aljudy" <hasan.aljudy at gmail.com> wrote in message  
>> news:du56te$1rn5$1 at digitaldaemon.com...
>>> friendship works, my point was that it shouldn't be there in the first  
>>> place, it's not part of the OO paradigm, it's a hack introduced by C++
>>  Just because it's not part of some archaic OO paradigm doesn't mean it  
>> can't exist.  It might be a hack, but I think it's kind of borne out of  
>> necessity. Sometimes the rules in OO need to be .. bent a little, and  
>> friend classes do just that.  I mean, which would you rather have?  Two  
>> classes that need to work together friended so they can access each  
>> others' internals, and so no one else can access those internals?  Or  
>> be required to make those internals public just so those classes can  
>> work together?  If two classes really need to work together but still  
>> need to be separate classes, I really don't see any other solution..
>
> Well, do people use your *ORGANS* when you work with them?

No. However a better analogy is "I will let my neighbour come over and use  
my basketball hoop, but not the general public."

class Me {
   private BasketBallHoop hoop;
}

class Neighbour {
   void playSomeBall(BasketBallHoop hoop) {}
}

void main()
{
   Neighbour bob = new Neighbour();
   Me regan = new Me();
   bob.playSomeBall(regan.hoop);
}

Regan



More information about the Digitalmars-d mailing list