c++ - Appropriate use of friend? Container class designed to manipulate objects of specific type -


You say that you have a FooManager to manage many types of objects Foo . FooManager needs to see parts of its Foo s to evaluate its current state before I see Foo < / Code> was using some accessories, until I realized that FooManager is actually the only class using these. I decided to make a friend of FooManager to Foo . As a result most of the classes Foo become private.

Is this a friend's fair use? My reasoning was that it helps in encapsulation because when it gives full access to the interior of FooManager to Foo , then it will completely stop access to everything else. Does.

Unless you are trying to achieve, there is no separate and cleaner way, It seems like a proper approach.

In relation to the encapsulation, see:.


Comments