Search code examples
umlclass-diagram

How to draw two references from one class to another in a UML class diagram?


Imagine the following case: I have a class Method and a class DataType. A method has one return type (if we count void as a return type) and zero to many parameters. Both the return type and the parameters are instances of the class DataType.

How would I model this Situation in a UML class diagram? One line for two references or one for each?

Solution A, one line: Solution A: one line

Solution B, two lines: Solution B: two lines


Solution

  • The best way would be to use role names instead:

    enter image description here

    Role names are explicit attributes in the opposite class, telling how the specific class is used. So Method.parameter is of type DataType.

    Note that I changed the return type to be 0..1 rather than 1 since your text tells that it's optional.