UML Diagram Examples: Class, Use Case, State and Activity
UML has fourteen diagram types, but four of them cover almost every project report and design review. Here is one solid example of each, with the notation explained so you can draw your own.
UML · 2026-10-23 · 9 min read
Class diagram
A class diagram shows the classes of a system, their attributes and methods, and how they relate. The relationship arrows matter:
| Line | Name | Meaning | Example |
|---|---|---|---|
| Hollow triangle ▷ | Inheritance | "is a" | Ebook is a Book |
| Filled diamond ◆ | Composition | Part cannot exist without the whole | Order ◆— OrderLine |
| Hollow diamond ◇ | Aggregation | Part can exist on its own | Library ◇— Book |
| Plain line | Association | Classes use each other | Member — Loan |
| Dashed with triangle | Realization | Class implements an interface | CardPayment ⇢ Payment |
Example: Class diagram for a library: members, books, loans and fines with multiplicities.
Use case diagram
A use case diagram shows who uses the system (actors, drawn outside the box) and what they can do (use cases, ovals inside the system boundary). Use «include» for a step that always happens as part of another use case, and «extend» for an optional one.
Example: Use case diagram for an ATM: customer and bank actors, withdraw, deposit, check balance.
State diagram
A state (state machine) diagram shows the states one object goes through and the events that move it between them — perfect for orders, tickets, documents and devices.
Example: State diagram for an online order: placed, paid, shipped, delivered, cancelled.
Activity diagram
An activity diagram is UML's flowchart, with extras: forks and joins (thick bars) for steps that run in parallel, and swimlane partitions for who does what.
Example: Activity diagram for exam registration with a decision and parallel steps.
Which UML diagram should you use?
| You want to show… | Use |
|---|---|
| The data model and code structure | Class diagram |
| What users can do with the system | Use case diagram |
| How one object changes over time | State diagram |
| The steps of a process or algorithm | Activity diagram |
| Messages between parts of the system | Sequence diagram |
Frequently asked questions
Which UML diagrams are needed for a final-year project?
Usually a use case diagram, a class diagram, a sequence diagram for the main flow, and an activity diagram. Many reports also include a DFD and an ER diagram.
What is the difference between aggregation and composition?
In composition the part cannot exist without the whole (an order line without its order); in aggregation it can (a book without a particular library).
Is an activity diagram the same as a flowchart?
Nearly. An activity diagram adds parallel steps (fork/join) and partitions, and uses UML notation.