Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 39 ยท Getting Started

The 14 UML Diagram Types

A tour of all 14 UML 2 diagram types, split into structure and behavior families, with one question each answers and a guide to which ones you will use most.

UML 2 defines fourteen diagram types. That sounds like a lot, but they fall into two clear families, and most projects lean on only a handful. This lesson gives you the map so that every later lesson has a place to sit on it.

The two families

Structure diagrams show what exists in the system, independent of time: classes, objects, components, machines. Behavior diagrams show what happens: users doing things, steps in a process, messages between objects, changes of state. Interaction diagrams are a sub-family of behavior diagrams that focus on message exchange.

flowchart TD
    D["UML 2 diagrams"] --> S["Structure (7)"]
    D --> B["Behavior (7)"]
    S --> S1["Class"]
    S --> S2["Object"]
    S --> S3["Component"]
    S --> S4["Composite structure"]
    S --> S5["Package"]
    S --> S6["Deployment"]
    S --> S7["Profile"]
    B --> B1["Use case"]
    B --> B2["Activity"]
    B --> B3["State machine"]
    B --> I["Interaction (4)"]
    I --> I1["Sequence"]
    I --> I2["Communication"]
    I --> I3["Timing"]
    I --> I4["Interaction overview"]

The 14 diagram types: 7 structure, 3 plain behavior, and 4 interaction diagrams.

Structure diagrams

Diagram The question it answers Where you learn it
Class What types exist and how do they relate? Classes and Members
Object What does one concrete snapshot of the system look like? Object Diagrams
Component What are the replaceable building blocks and their interfaces? Chapter 5
Composite structure What is the internal wiring of one class or component? Chapter 5
Package How are model elements grouped, and what depends on what? Chapter 6
Deployment Which software runs on which hardware or runtime? Chapter 6
Profile How do I extend UML for my own domain? Notation Essentials

Behavior diagrams

Diagram The question it answers Where you learn it
Use case What can each kind of user do with the system? Use Case Basics
Activity What are the steps and decisions of a process? Activity Diagram Basics
State machine How does one object change status over its life? Chapter 5
Sequence Which messages are sent between objects, in order? Sequence Diagram Basics
Communication Which objects talk to each other, and how are they linked? Communication Diagrams
Timing How do states change along a time axis? Chapter 5
Interaction overview How do several interactions fit into one flow? Chapter 4 and 5

Same system, different views

Take an online library. Each diagram answers a different question about the very same system.

One library, five views

Use case Members borrow books.
Class Book, Member, Loan.
Activity Check out, scan, confirm.
Sequence UI asks Service asks DB.

Each view hides what it does not need.

1 / 2

Here are two views of one tiny slice of that library. First the structure.

classDiagram
    class Member {
        +String name
        +borrow(Book b)
    }
    class Book {
        +String title
    }
    Member "1" --> "*" Book : borrows

And now the same idea as behavior: one interaction.

sequenceDiagram
    actor M as Member
    participant S as LibraryService
    M->>S: borrow(book)
    S-->>M: loan confirmed

Notice that neither diagram contradicts the other. They simply emphasize different things.

Python Classify diagrams by family

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Which ones will you actually use?

Surveys and experience agree on a rough ranking for working developers:

  1. Class and sequence diagrams, almost daily in design discussions.
  2. Use case and activity diagrams during requirements and process modeling.
  3. State machine diagrams for anything with a life cycle (orders, connections, devices).
  4. Component and deployment diagrams for architecture overviews.
  5. The rest (composite structure, timing, interaction overview, profile) when the problem calls for them, often in embedded or telecom work.

You do not need to master the rare ones to be effective, but you should recognize them.

UML diagrams are not isolated pictures. The elements in them (a class, an actor, a lifeline) live in one underlying model. Good tools keep them consistent; with plain drawing tools you keep consistency by hand.

Choosing the right diagram

A helpful decision rule: start from the question, not from the diagram.

  • "What are the words in our domain?" Draw a class diagram.
  • "Who uses this and why?" Draw a use case diagram.
  • "How does this process flow?" Draw an activity diagram.
  • "How do these objects collaborate in this scenario?" Draw a sequence diagram.
  • "What can happen to this thing over time?" Draw a state diagram.
  • "Where does this run?" Draw a deployment diagram.
Python A question-to-diagram lookup

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which family does a class diagram belong to?

    Class diagrams show what exists (types and relationships), so they are structure diagrams.
  2. 2. Which of these is an interaction diagram?

    Sequence, communication, timing and interaction overview diagrams show message exchange.
  3. 3. You need to describe the life cycle of an order (new, paid, shipped). Which diagram fits best?

    State machine diagrams show the states of one object and the events that move it between them.
  4. 4. How many diagram types are there in total in UML 2?

    Seven structure diagrams and seven behavior diagrams, four of which are interaction diagrams.
  5. 5. What should drive your choice of diagram?

    Pick the view that answers the question in front of you.

Summary

  • UML 2 has 14 diagrams: 7 structure and 7 behavior (4 of them interaction diagrams).
  • Structure diagrams show what exists; behavior diagrams show what happens.
  • Class, sequence, use case, activity and state diagrams cover most daily needs.
  • Different diagrams are views of one model and should not contradict each other.
  • Choose a diagram by the question you are asking.

Next: Modeling Tools and Mermaid