# UML Class Diagram

**In short:** A UML class diagram shows classes and how they relate. Use it as a selective sketch of the interesting classes, not as a full specification of every class.

## Explanation

A class diagram shows classes and the links between them. See UML Class Diagram Relationship for the full set of relationship types.

**Associations.** An association is a line between two classes. It usually stands for something like a field in a class. If class A holds a reference to class B, you draw an association from A to B.

**Dependencies.** A dependency means that a change to one element (the supplier) may force a change in another (the client). Associations and generalizations already imply a dependency. So there is no need to draw an extra dependency line next to them.

**Interfaces.** UML 2 added the socket notation to show interfaces a class requires. It grew out of the lollipop notation, which shows interfaces a class provides. The UML committee ruled that the combined ball-and-socket notation may only be used for connectors in Composite Structure Diagrams. It does not link interfaces in class diagrams. See Provided and Required Interface for more.

**Stay selective.** Use class diagrams as sketches. Show only the classes that are interesting and worth discussing before you read the code. The goal is communication, not a complete specification. Showing every class makes the diagram harder to understand.

## Example

A team sketches an online shop. The diagram shows three classes: Order, Customer and Product. An association from Order to Customer reflects that an order holds a reference to its customer. Helper classes stay out of the picture. The team uses the sketch to agree on the core ideas before looking at code.

## Trade-offs

A selective sketch is quick to read and good for discussion. It leaves classes out, so it is not a complete specification. Drawing every class would be more complete, but it would hurt comprehensibility.

A selective sketch: three classes, with associations that read like fields.

```plantuml
@startuml
class Order
class Customer
class Product
Order --> Customer : placed by
Order --> "1..*" Product
@enduml
```

## Checks

- The class diagram shows only the interesting classes, not every class in the system.
- Dependency lines are not drawn in addition to associations or generalizations between the same classes.
- The ball-and-socket notation is not used to link interfaces in class diagrams.

## Related

- [UML Class Diagram Relationship](https://arc.fuet.ch/concepts/modeling-uml/class-diagram-relationships.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)
- [UML Generalization and Specialization](https://arc.fuet.ch/concepts/modeling-uml/generalization-and-specialization.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 Structure Diagram](https://arc.fuet.ch/concepts/modeling-uml/structure-diagram.md)

## Sources

- [Uml As Sketch](https://martinfowler.com/bliki/UmlAsSketch.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
