Search code examples
umlsoftware-designclass-diagram

How to represent a class' relationship when the class is only used as a data type


I can't find an exact answer to this question when drawing a class diagram.

I have a class, that contains properties, and a method for external access to the data associated with that property.

It will exist within two other classes in the diagram as the datatype to the other property, the other class will hold an array of this class' instances.

What I currently have drawn

I was unsure how to represent this in the diagram, my first thought was a compositional relationship but that doesn't seem quite right.


Solution

  • In UML a property can be an attribute of the class or the owned end of an association of that class. Semantically there’s almost no difference.

    Therefore, the way one object instance is “included” in another is open to interpretations in UML diagrams, as different language have different constructs and semantics for implementing object composition. The common techniques are:

    • If it is a data type in every case, the keyword «datatype» can be used. It means that it has a value semantic like the build-in types. You can use either an association or an attribute with the datatype as type.
    • If it is important that included instances are owned by the including instance and deleted when the including instance deceases, the composition is a good candidate.
    • In all other cases you can simply use an association, preferably but not necessarily with the dot notation on the owned end (many popular tools don’t support that notation).

    Whatever you chose, keep in mind that you’d better focus in the UML diagram on the semantic relationships between these classes rather than the precise implementation of these relations (which the “inclusion” in a programming language class is)