Search code examples
c++boostumlshared-ptrsmart-pointers

Drawing Smart Pointers in UML


Is there a generally accepted way of depicting objects held by a shared pointer (boost::shared_ptr or std::shared_ptr) in a UML class diagram? In particular, should one use and empty or full diamond like aggregation or composition?


Solution

  • I am not aware of an overall consensus on how to model smart pointers as relations.

    A black diamond means controlling life time, a white diamond means not controlling life time, so you could agree locally to use black diamonds for unique_ptr, all black diamonds for shared_ptr and white diamond for weak_ptr.

    If you really want to model smart_ptr, I would suggest adding a property class to the relation:

    0
    |  /----------------\
    +--+ shared pointer |
    |  \----------------/
    V