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