Topic: Solution to "partial friendship" problem
Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Mon, 17 Dec 2001 17:23:28 GMT Raw View
In article <9vl27i$g0de7$1@ID-47792.news.dfncis.de>, Bo-Staffan Lankinen says...
>
>> That's one way to do what you want to do, with the risks you noted.
>> However, class<N> might have member classes up, down which befriend
>> class<N+1> and class <N-1>. These member classes wouldn't have data,
>> and only have private inline functions that access the part of class<N>
>> you want exposed to class<N+1> cq class <N-1>.
>> No objects of these member classes are ever created, and the inline
>> functions can be trivial forwarding functions. That won't cause
>> overhead.
>> This mechanism can be used to provide fine-grain access control at the
>> "expense" of naming these access methods. I think that's a benefit, not
>> a real expense.
>
>No, that wouldn't solve the fundamental problem that one want to expose only
>a subset of the private interface to another class. The up/down interfaces
>still needs to be friend of both class<N> and class<N+1>, ie. it's possible
>to inadvertly invoke the private implementation from the member interfaces.
>The only safe way, as I see it, to prevent this, would be to create an
>abstract interface, make that interface a friend of one of the classes and
>let the other class derive from/override that interface.
>
>Bo-Staffan
You're misunderstanding things. The "up" member class of class <N> doesn't
need to be a friend of class<N+1>. It doesn't access class<N+1>. Instead,
class<N+1> is a friend of class<N>::up - the other way around. In this way,
class<N>::up is nothing but a listing of the subset of class<N> functions
available only to class<N+1> "up" doesn't have implementations of anything.
HTH,
--
Michiel Salters
Consultant Technical Software Engineering
CMG Trade, Transport & Industry
Michiel.Salters@cmg.nl
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]