views:

29

answers:

1

Lets say you have a FooManager made to manage multiple objects of type Foo. The FooManager needs to see some parts of its Foos to evaluate their current state. Before I was using a few accessors in Foo to see these parts, until I realized that FooManager is the only class actually using these. I decided to make FooManager a friend of Foo. This resulted in most of class Foo becoming private.

Is this an appropriate use of friend? My reasoning was that it helps encapsulation because while it gives FooManager complete access to Foo's internals, it completely blocks off access to everything else.

+1  A: 

Unless there is a different and cleaner way to achieve what you're trying to achieve, this sounds like a fair approach.

With regards to encapsulation, see: http://www.parashift.com/c++-faq-lite/friends.html#faq-14.2.

synhershko
I actually used the Attorney-Client idiom that one guy posted, but unfortunately his answer his gone. Oh well.
random