UML class diagram

Classes with attributes and operations, inheritance, composition and dependencies.

1 uml class diagram example

Invoice class model

An invoice that extends a document, implements a payable interface and owns its line items.

The arrowheads carry the meaning: a hollow triangle for inheritance, dashed for an interface, a filled diamond where the part dies with the whole. The class being implemented takes the accent.

Open in the editor

What is a UML class diagram?

A UML class diagram shows the classes in an object-oriented system, their attributes and operations, and the relationships between them. It is the most widely used structural diagram in UML.

Each class is a box with three compartments: name, attributes and methods, with + and - marking public and private. A hollow triangle means inheritance, a filled diamond composition, a hollow diamond aggregation and a dashed arrow dependency.

When to use a UML class diagram

  • Use it to design a domain model, such as an invoice with line items, taxes and payments, before implementation.
  • Use it to document the core types of a library or service for new contributors.
  • If you only need to show stored data and relationships, an ER diagram is simpler and reaches a wider audience.

How to make a good UML class diagram

  1. Show the classes that matter for the question at hand, not the whole codebase.
  2. Include only the attributes and methods that explain behavior; skip getters and setters.
  3. Use the correct arrow for each relationship, since composition and aggregation mean different lifecycles.
  4. Add multiplicities, like 1 and 0..*, on associations.