How can I describe a pointer to class in a UML class diagram?

A plain C++ pointer directly corresponds to a reference property in a UML class diagram, as shown in the following diagram:

enter image description here

Such a reference property expresses a uni-directional (binary) association, as shown in the following diagram:

enter image description here

Notice the "dot" at the B side of the association line. It means that the association end with name "attribute" is owned by class A, which means that it corresponds to the reference property shown in the diagram above (the association can be replaced with the reference property). For more explanation see Chapter 5 of this tutorial.

You cannot use the C++ symbol "*" in the UML class diagram because

  1. it is Cpp-specific, while your diagram should probably be platform-independent;
  2. there is no need to use such a symbol in UML because it's clear that the attribute references B objects;
  3. this symbol has a different meaning in UML (the multiplicity unbounded).

In any case, the relationship between the classes A and B is an association. It may be a composition, if you have the additional semantics of an aggregate-component relationship. Notice that your question should be worded: "What kind of association is it?" instead of "What kind of composition is it?" because composition and aggregation are special types of associations.


In UML it is not as important to show whether it is a pointer or not. Why? Because, you may be using UML describing an OOD for a language without pointers.

Quick answer: from your code, A aggregates B (empty diamond at A class, connecting B with a solid line). That is because there is no destructor that deletes what A.attribute pointer references.

What is really important is to say what is the lifetime of the referenced object. So, for a referenced object (has relationship) that dies when the owner is destroyed, you have to use a solid (filled) diamond. This is called composition. So the owner has to manage the life time of the owned object. One such example is human has hands. The hands do not survive when the human object is destroyed.

When the diamond is not filled (aggregation), then the owner is not responsible to manage the life of the object owned. For example you will not expect to see that the owned object being deleted in the destructor. An employer has a TeamLeadRole, but when the employer is "destroyed" (i.e. left the company) then the TeamLeadRole is still available.

Now, traditionally when you see a filled diamond, you usually (not all the time) will have an object by value. Where when you see an empty diamond you may use reference, or pointer.

If your class uses another class but does not keep instances (or references/pointers) to that class, then you can denote dependency by just a simple line (solid) between the objects. That means there is a relationship is called association.