🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2943

Re: Encapsulation and friends

#2943
From: Herb Sutter
Date: Fri, 15 Dec 1995 09:14
40 lines
2256 bytes
In article <4apdff$eos@mhost.ida.his.se>,
   anders@ida.his.se (Anders Eklund) wrote:
>Friends break the rules of encapsulation and should be avoided

No.  See FAQ #24 (http://www.connobj.com/cpp/cppfaq.htm).

>as much as possible, but sometimes they must be used anyway.
>When I have used friends they only had to use one or a
>few members of the class. As it is now all members are
>accessible to the friend. I would like to specify which members
>the friend can access. There is no way to do that today, but
>would it not be nice to be able to do so? Any comments?

In general, having partial friendship (to only certain parts of a class) would 
be a (meagre) step in the direction of what Reenskaug et al describe in their 
OOram book in terms of objects playing different roles at different times, and 
that a particular method in a given object may only be accessed by certain 
roles.  However, partial friendship isn't enough to let you implement what 
Reenskaug is talking about, mainly because friendship isn't inherited.

If friendship were heritable, then you could use mixins to solve the general 
problem of granting friendship to only parts of a class.  I'm about to ask a 
question without having done my homework, but: what were the main reasons 
again for not making friendship heritable (even as an option)...?	

Herb


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herb Sutter (herbs@connobj.com)

Connected Object Solutions     2228 Urwin - Suite 102     voice 416-618-0184
http://www.connobj.com/      Oakville ON Canada L6L 2T2     fax 905-847-6019


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <4aqsbs$508@steel.interlog.com>
Path: arc1-ca.pugleaf.net!tcsi.tcs.com!agate!agate!matt
References: <4apdff$eos@mhost.ida.his.se>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!tcsi.tcs.com!agate!agate!matt
From: herbs@connobj.com (Herb Sutter)
Newsgroups: comp.std.c++
Subject: Re: Encapsulation and friends
Date: 15 Dec 1995 09:14:06 GMT
Organization: Connected Object Solutions
Approved: matt@Austern (Matt Austern)
Message-ID: <4aqsbs$508@steel.interlog.com>
References: <4apdff$eos@mhost.ida.his.se>
NNTP-Posting-Host: austern.hip.berkeley.edu