UML Diagram Examples: Class, Use Case, Sequence, State and Activity
UML has fourteen diagram types, but five of them cover almost every project report and design review: class, use case, sequence, state and activity. Below is a real example of each, with the notation explained, and every example opens as an editable template.
UML · 2026-11-03 · 11 min read
Types of UML diagrams
UML 2 splits its 14 diagrams into two groups. Structure diagrams show what the system is made of; behaviour diagrams show what it does over time.
| Group | Diagram | Shows |
|---|---|---|
| Structure | Class diagram | Classes, attributes, methods and relationships |
| Structure | Component / deployment diagram | Software parts and the servers they run on |
| Structure | Object, package, composite structure, profile | Less common; mostly in large designs |
| Behaviour | Use case diagram | Who uses the system and what they can do |
| Behaviour | Sequence diagram | Messages between parts, in time order |
| Behaviour | State diagram | The states one object moves through |
| Behaviour | Activity diagram | The steps of a process, with parallel paths |
| Behaviour | Communication, timing, interaction overview | Less common variants of sequence diagrams |
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.
A second example, with more actors: in a food delivery app each kind of user gets their own use cases inside the same system boundary.
Example: Use case diagram for a food delivery app.
Sequence diagram
A sequence diagram shows the messages between parts of a system in time order. Each participant gets a vertical lifeline; solid arrows are calls, dashed arrows are replies, and boxes labelled alt or loop show choices and repeats.
Example: Sequence diagram for login with OTP: user, app, auth service and SMS gateway.
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.
How many types of UML diagrams are there?
UML 2 has 14: seven structure diagrams (class, component, deployment, object, package, composite structure, profile) and seven behaviour diagrams (use case, activity, state, sequence, communication, timing, interaction overview).
Can I edit these UML examples?
Yes. Every example on this page opens in AI Flowchart as an editable diagram, and you can ask the AI to change it for your own system.