To design my code I am drawing some UML Class diagram. I have some shared objects and I am wondering how that should be drawn since the ownership of these objects is really shared. To be more specific here a C++ example of what is happening:
class A
{
public:
A(){
std::shared_ptr<CSharedObj> sharedObj = std::make_shared<CSharedObj>;
mB = B(sharedObj);
}
private:
B mB;
};
class B
{
public:
B(std::shared_ptr<CSharedObj>);
private:
std::shared_ptr<CSharedObj> mSharedObj;
};
class CSharedObj
{
public:
CSharedObj();
};
How do I represent in a class diagram the relationship between these 3 classes?
B
need shared ownership ofCSharedObj
? The lifetime ofB
is the same as the lifetime ofA
so it could safely have a non-owning pointer toCSharedObj
, no? – BookerbookieB
that makes more sense and I didn't spot thatA
doesn't store the shared object. – BookerbookieA
andB
. – Allina