Looking on this answer I understand that you should not copy private pointers using friendship in C++ like I did in my program:
class bar;
class foo
{
private:
some_smart_pointer<int> state;
public:
foo(int value) : state(new int(value)) {}
friend class baz;
};
class bar
{
private:
some_weak_pointer<int> state;
public:
friend class baz;
};
class baz
{
public:
foo Foo;
bar Bar;
baz() { Bar.state = Foo.state; }
};
That's ok but passing a constant smart pointer violates the principle of encapsulation.
It exposes the internals of the system.
Passing bar to foo also creates coupling.
Also in my system it makes sense to aggregate objects to what is called in that question a fluent interface:
MainObject.PropertyCollection.Property
As it's said in that SO answer it does not violate the Law of Demeter or does it?
I'm extremely confused here.
I'm redesigning my library for the last time and I want it to be right.
I thought that instead of passing my internal smart pointer I should pass a wrapper class that will also be used as a property and set it to read only and then copying is safe right?
EDIT according to comments:
Well I'm implementing the D20 3.5 SRD (http://www.d20srd.org/).
For instance there are six abilities.
In my design D20Abilities is aggregated inside D20Character.
D20Abilities contains 6 D20Ability instances: Strength, Dexterity, Constitution. Wisdom, Intelligence and Charisma.
All of the D20Ability instances hold a private state (which is called modifier) that is shared throughout the system.
For instance each skill needs his own ability's modifier.