How do I show map in UML? C++

Viewed 215

I have a "Database" class that has a template "myMap" that stores instances of the "Client" class. The "myMap" consists of nodes (instances of the "Node" class). How do I show this in UML?

template<typename KEY, typename VALUE> class myMap;

template <typename KEY, typename VALUE>
class Node
{
private:
    friend class myMap<KEY, VALUE>;
    KEY id;
    VALUE object;
    Node* parent;
    Node* left;
    Node* right;
};

template<typename KEY, typename VALUE>
class myMap
{
    Node<KEY, VALUE>* root;
    ////
};

class Client
{
    int id;
};

class Database
{
    myMap<int, Client> clients;
};
1 Answers

A map between type K and type V, noted in C++ with std::map<K,V> is typically modelled in UML using an association with a qualifier, the qualifier being of type :K and the other end of the association being of type V.

The qualifier is used in conjunction with a source type T that is at the first end of the association. In C++, this means that the map would be a member of T. In your case it would be Database.

Related