# UML Class Diagram Relationship

**In short:** UML class diagrams use different relationship types to link classes. Pick the type that matches the real link: associations resemble fields, composition means single ownership, and aggregation adds no meaning beyond association.

## Explanation

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.

## Example

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.

## Trade-offs

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.

```plantuml
@startuml
class Order
class OrderLine
class Customer
Order *-- "1..*" OrderLine : contains
Order --> "1" Customer : placedBy
@enduml
```

## Checks

- 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.

## Related

- [UML Class Diagram](https://arc.fuet.ch/concepts/modeling-uml/class-diagram.md)
- [UML Association](https://arc.fuet.ch/concepts/modeling-uml/association.md)
- [Aggregation vs. Composition](https://arc.fuet.ch/concepts/modeling-uml/composition-versus-aggregation.md)
- [Provided and Required Interface](https://arc.fuet.ch/concepts/modeling-uml/provided-and-required-interface.md)
- [UML Interface](https://arc.fuet.ch/concepts/modeling-uml/uml-interface.md)
- [Common Class Diagram Modeling Mistakes](https://arc.fuet.ch/concepts/modeling-uml/common-class-diagram-modeling-mistakes.md)
- [UML Generalization and Specialization](https://arc.fuet.ch/concepts/modeling-uml/generalization-and-specialization.md)
- [Instance Specification](https://arc.fuet.ch/concepts/modeling-uml/instance-specification.md)

## Sources

- [Aggregation And Composition](https://martinfowler.com/bliki/AggregationAndComposition.html) — martinfowler.com, accessed 2026-11-09
- [Dependency And Association](https://martinfowler.com/bliki/DependencyAndAssociation.html) — martinfowler.com, accessed 2026-11-09
- [Ball And Socket](https://martinfowler.com/bliki/BallAndSocket.html) — martinfowler.com, accessed 2026-11-09
