Card 02/ 08
UML Relationships and Their Arrows
Inherits, implements, has, owns, knows and uses: six relationships, each drawn differently.
A UML class diagram draws six kinds of relationship between classes, and each one has its own combination of line and arrowhead. The line is solid or dashed, and the end carries a triangle, a diamond or an open arrow. This card names all six, says what each means, and gives the code each one usually becomes.
The diagram shows each relationship once, between a pair of classes chosen so the meaning is easy to say aloud.
| Relationship | Drawn as | Read it as | Usually in code |
|---|---|---|---|
| Inheritance | Solid line, hollow triangle at the parent | A dog is an animal. | class Dog(Animal) or extends |
| Realisation | Dashed line, hollow triangle at the interface | A bird implements flying. | implements Flyer, or a class that matches a protocol |
| Association | Solid line, open arrow at the class it knows | A teacher knows their courses. | A field holding the other object |
| Aggregation | Solid line, hollow diamond at the whole | A team has players, who can leave it. | A field holding parts passed in from outside |
| Composition | Solid line, filled diamond at the whole | A house owns its rooms, which go when it does. | A field holding parts the whole creates itself |
| Dependency | Dashed line, open arrow at the class it uses | A report uses a printer for a moment. | A parameter or a local variable |
Two rules sort most of the table. A triangle always means "is a kind of": solid for a class, dashed for an interface. A diamond always sits on the whole, never the part: hollow when the part has a life of its own, filled when the whole creates and destroys it.
The remaining two are about how long one class holds the other. Association is a lasting link, kept in a field. Dependency is a passing one, an object received as a parameter or created inside one method and forgotten afterwards, which is why its line is dashed.
Most pattern diagrams use only four of the six: inheritance, realisation, association and dependency. Aggregation and composition appear where a pattern builds a whole from parts, as Composite and Builder do.
← → move through sections and cards