UML class diagram
For OOP: classes, attributes, methods and relationships.
What it explains and when it is useful
A UML class diagram shows the classes in an object-oriented program: their attributes and methods with visibility and types, and the relationships between classes with multiplicities.
When to use it: Solutions written in an object-oriented way (Java, C#, Python classes, Swift). Show the classes that matter to your design, not every library class.
Worked example
Illustrative: PracticePal is a fictional project used throughout this guide.
Alternative version. The main PracticePal is procedural (see the structure chart). This diagram shows how the same design would look written in an object-oriented style, for example in Java.
Scroll sideways to see the whole diagram.
Notation and legend
| Symbol or part | Meaning |
|---|---|
| Three-part box | Class name; attributes; methods |
| - / + | private / public (# = protected) |
| Underlined | static (belongs to the class, not each object) |
| Line | Association; numbers are multiplicities (1, 0..*) |
| Hollow diamond | Aggregation, at the whole (a Waitlist holds Students that exist without it) |
| Filled diamond | Composition (parts die with the whole) |
| Hollow triangle | Inheritance, at the parent |
| Dashed arrow «uses» | Dependency: uses another class without storing it |
Design decisions it communicates
A diagram earns marks when you explain the decisions it shows. In PracticePal's documentation these would each be one sentence:
- BookingService holds the rules, so Booking objects stay simple data with behaviour about themselves (checkIn, overlaps).
- MAX_PER_WEEK is static: one limit for all bookings.
- Room keeps a set of neighbours, which is the graph used for the noise rule.
Common mistakes
- Drawing database tables and calling them classes (no methods = probably an ERD).
- Leaving out multiplicities.
- Diamonds at the wrong end.
- Listing every getter and setter instead of meaningful methods.
Checklist for your own version
Ticks are saved in this browser only, so you can use the list while you draft.