Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 39 ยท Modeling Practice

Choosing the Right Diagram

Pick the right UML diagram for the question you need to answer: audience, abstraction level and purpose, with a decision table, a model-first workflow and a runnable chooser.

UML has 14 diagram types, and no project needs all of them. The most common modeling mistake is not drawing a diagram wrongly, but drawing the wrong diagram: a class diagram to explain a workflow, a sequence diagram to explain data, or a deployment diagram when the question is about behavior. This lesson gives you a method for choosing.

Start with the question, not the diagram

A diagram is an answer to a question. Write the question first.

Question Diagram
Who uses the system and what do they want to achieve? Use case diagram
What is the business process or algorithm, with decisions and parallel work? Activity diagram
What are the concepts and relationships of the domain or code? Class (or object) diagram
What are the relationships between concrete instances right now? Object diagram
In which order do participants exchange messages in this scenario? Sequence diagram
Which participants are linked, ignoring time? Communication diagram
How do scenarios chain together? Interaction overview diagram
Which timing limits apply? Timing diagram
What are the lifecycle rules of one object? State machine diagram
What are the big replaceable parts and their interfaces? Component diagram
How is one part built from internal parts? Composite structure diagram
Where does the software run? Deployment diagram
How is the model organized into layers or modules? Package diagram

Looking at this table, you can see that diagrams fall into two families:

  • Structure diagrams describe what exists: class, object, component, composite structure, deployment, package, profile.
  • Behavior diagrams describe what happens: use case, activity, state machine, and the four interaction diagrams (sequence, communication, timing, interaction overview).

A good model uses at least one of each: structure gives the nouns, behavior the verbs.

flowchart TD
    Q{"What do you need to explain?"}
    Q -->|"what exists"| S{"At what level?"}
    Q -->|"what happens"| B{"What scope?"}
    S -->|"concepts, code"| C["Class diagram"]
    S -->|"big parts"| K["Component diagram"]
    S -->|"hardware"| D["Deployment diagram"]
    B -->|"user goals"| U["Use case diagram"]
    B -->|"process"| A["Activity diagram"]
    B -->|"messages, one scenario"| SQ["Sequence diagram"]
    B -->|"object lifecycle"| ST["State machine diagram"]

A first-cut chooser: start from the question, end at one diagram.

Audience and level of detail

The same system needs different diagrams for different readers.

Audience Needs Typical diagrams Detail
Customer, business Goals, process, vocabulary Use case, activity, domain class diagram Low
Architect, tech lead Structure, interfaces, deployment Component, deployment, package Medium
Developer How to build this part Class, sequence, state High
Tester Scenarios, states, paths Sequence, activity, state, use case High
Operations Runtime topology Deployment Medium

Always label the diagram with its level: conceptual (domain words), specification (interfaces and responsibilities) or implementation (matching the code). Mixing levels in one picture, such as a domain concept next to a HashMap field, confuses readers.

Sketch, blueprint, or programming language?

Martin Fowler's classic distinction names three ways to use UML:

  1. Sketch: quick, informal drawings on a whiteboard to communicate and think. Throw them away.
  2. Blueprint: detailed design documents, often drawn before coding, sometimes used to generate code.
  3. Programming language: executable models, where the model is the program.

Most teams use UML as a sketch: a few boxes and arrows, drawn to discuss one design problem, then photographed or redrawn in text form. This is the sweet spot. Blueprint use pays off in regulated or safety-critical systems. Executable UML remains niche.

Match the effort to the use: do not make a polished blueprint of something that will change tomorrow.

A practical modeling workflow

A workflow that works for most projects:

  1. Use cases capture goals (what the system is for).
  2. A domain class diagram (concepts only) agrees on vocabulary.
  3. Activity diagrams for the two or three non-trivial processes.
  4. Sequence diagrams for the key scenarios, which reveal the operations that classes need.
  5. A refined class diagram that now carries the discovered operations.
  6. State machine diagrams for the few objects with real lifecycles.
  7. Component and deployment diagrams when you decide structure and infrastructure.

Notice that you do not model everything. You model what is risky, unclear or shared by several people. Straight CRUD screens do not need a sequence diagram.

Consistency between diagrams

Diagrams are views of one model, so they must agree. Check:

  • Every message in a sequence diagram corresponds to an operation of the receiver's class.
  • Every state-machine event is an operation or signal in the class diagram.
  • Every actor in a use case diagram appears as a role in at least one sequence or activity diagram.
  • Every component in the deployment diagram has an artifact that manifests it.

Keeping a simple traceability table (use case to scenarios to classes to tests) pays off in review.

A diagram chooser in code

The decision table above is data. A small function turns the question into a recommendation, which is a fun way to test whether your own rules are consistent.

Python Recommend a diagram from keywords

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.

Counting what you have

After a while, projects collect many diagrams. A quick inventory shows gaps: structure without behavior, or the reverse.

Python Check the balance of a model

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 ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which diagram best answers 'what are the permitted lifecycle changes of an order?'

    Lifecycle rules of one object are the purpose of state machines.
  2. 2. Which are structure diagrams?

    Structure shows what exists; behavior shows what happens.
  3. 3. What does 'UML as a sketch' mean?

    Most teams use UML informally to discuss a design problem.
  4. 4. A message in a sequence diagram has no matching operation in the receiver's class. What is wrong?

    Diagrams are views of one model and must agree.

Summary

  • Choose a diagram by the question and the audience; every diagram answers one kind of question.
  • Use both structure and behavior views; model what is risky or unclear, not everything.
  • Label the level of abstraction: conceptual, specification or implementation.
  • Most teams use UML as sketches; invest in blueprints only where the context demands it.
  • Keep diagrams consistent, with a traceability table if the project is large.

Next: OCL Constraints