Skip to content

UML Class Diagram Relationship

A UML class diagram shows classes and the links between them. UML offers several relationship types. Each says something different, so the choice should match the real link between the classes. See UML Class Diagram for the basics.

Association. An association is the general structural link. It usually stands for something like a field in a class. If an Order holds its items in a field, an association fits.

Dependency and required interfaces. Classes do not only implement interfaces. They can also require them. Thinking of a class as requiring an interface expresses a usage dependency. UML has a compact socket notation for a required interface. That ball-and-socket notation is limited to connectors in Composite Structure Diagrams. In UML 1, a class showed a required interface with a dependency. See Provided and Required Interface and UML Interface.

Composition. Composition is drawn with a black diamond. It carries real meaning. A part object can belong to only one composition at a time. Ordinary multiplicity markers cannot easily express this single-owner rule, so the diamond does that job.

Aggregation. Aggregation is drawn with a white diamond. It adds nothing beyond a plain association. Jim Rumbaugh called it a “modeling placebo”. It has no standard meaning, so add an explanation if you use it. See Aggregation vs. Composition.

Choosing. Ask what the link really is.

  • A field-like link: use an association.
  • One owner for a part: use composition.
  • Plain use of an interface: think of a required interface (a usage dependency).
  • A white diamond: use it only with a note that says what you mean.

A shop model has an Order, its OrderLines, and a PriceCalculator.

  • Order keeps its OrderLines in a field. Each line belongs to exactly one order. A black diamond on the Order side shows this single owner.
  • Order also holds a Customer in a field. A plain association shows that link.
  • Order needs a pricing interface that PriceCalculator provides. Order requires that interface, which is a usage dependency.

The diagram uses no white diamond. A reader never has to guess what it means.

Composition adds meaning, but it also adds a rule readers must know: one owner only. Plain associations are simpler, but they say less. Aggregation looks richer but carries no standard meaning, so it can mislead readers or force extra explanation. The socket notation for required interfaces is compact, but it works only in Composite Structure Diagrams.

Composition (black diamond) for an owned part, and a plain association for a field-like link.

Diagram source
@startuml
class Order
class OrderLine
class Customer
Order *-- "1..*" OrderLine : contains
Order --> "1" Customer : placedBy
@enduml
  • Associations are used for field-like structural links between classes.
  • Composition (black diamond) is used only where a part belongs to a single owner.
  • Any aggregation (white diamond) in the diagram comes with an explanation of what it means.
  • Required interfaces are shown with a notation that UML allows for that diagram type.