Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 50 ยท Modeling with UML

UML Overview

Learn what UML is for, the difference between structural and behavioral diagrams, and when a quick sketch beats a formal model. Includes a diagram picker.

The Unified Modeling Language (UML) is a standard visual notation for describing software. It gives teams a shared set of boxes, lines and arrows so that a designer in one country and a developer in another read the same picture the same way. UML does not tell you how to build software and it is not a programming language. It is a way to think and talk about a system before, during and after you build it.

This chapter walks through the diagrams you will meet most often. This first lesson is the map: what kinds of diagrams exist, what each is good for, and how much effort a diagram deserves. UML is a notation, not software you can run, so the diagrams here are read-only pictures. The runnable examples are JavaScript stand-ins: a small catalog that picks a diagram for a question, and a checker that tells structure from behavior. They model the idea of choosing a diagram; they are not UML tools.

Why model at all?

Code is precise but detailed. A thousand lines of source rarely answer "what are the main parts and how do they relate?" at a glance. A model leaves details out on purpose, so a reader can see one aspect of the system clearly. Models help you to:

  • Think before building. Finding a flaw on a whiteboard costs minutes; finding it in production costs days (see the cost of late change).
  • Communicate. Customers, testers and developers can discuss the same drawing.
  • Document. A diagram of the architecture helps a new teammate more than reading every file.
  • Analyze. Drawing a workflow often exposes a missing case, like "what happens if the payment fails?".

A model is always a simplification. Ask which question it answers, and leave out anything that does not help answer it.

Structural and behavioral diagrams

UML 2 defines 14 diagram types in two families.

Structural diagrams show what the system is made of: the parts that exist and how they connect, regardless of time.

  • Class diagram: classes, their data and operations, and relationships.
  • Object diagram: a snapshot of instances at one moment.
  • Component diagram: replaceable building blocks and the interfaces between them.
  • Deployment diagram: software artifacts placed on hardware nodes.
  • Package, composite structure and profile diagrams: grouping and extension mechanisms.

Behavioral diagrams show what the system does over time.

  • Use case diagram: who uses the system and for what goals.
  • Activity diagram: a flow of steps and decisions.
  • State machine diagram: the states one object passes through and what triggers each change.
  • Sequence diagram: messages between participants, in time order.
  • Communication, timing and interaction overview diagrams: variations on interactions.

Two families of diagrams

Structural What the system is made of.
Behavioral What the system does over time.

Most projects need a few diagrams from each family, not all fourteen.

1 / 2

Teams also use two close relatives outside the 14 UML types: data flow diagrams and entity-relationship diagrams. You will meet them at the end of this chapter, because they are handy for analysis and database design.

A first look at two diagrams

Here is the same tiny online shop viewed two ways. The structural view shows the parts; the behavioral view shows one interaction.

classDiagram
    class Customer {
        +String name
        +placeOrder()
    }
    class Order {
        +Date placedAt
        +total() Money
    }
    Customer "1" --> "*" Order : places

A class diagram: one customer places many orders. It says nothing about the order of events.

sequenceDiagram
    participant C as Customer
    participant S as Shop
    C->>S: placeOrder(items)
    S-->>C: confirmation

A sequence diagram: the customer sends a request and gets a reply. It says nothing about class attributes.

Neither diagram is complete, and neither should be. Together they answer different questions. The following lessons teach how to read and draw each one: use case diagrams, class diagrams, sequence and activity diagrams, and state, component and deployment diagrams.

Choosing a diagram for a question

Start from the question, not from the notation. The stand-in below holds a small catalog of questions and the diagram that usually answers each. It models the decision a designer makes; the pairings are common conventions, not strict rules. Run it to see the picks grouped by family.

JS Pick a diagram for each question

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

No output.

The matcher is crude word overlap, so it only works because the catalog is tiny. A human picks the diagram by thinking about the reader. The point is the habit: name the question first.

Sketch or formalize?

UML is used at very different levels of ceremony.

  • As a sketch. A quick drawing on a whiteboard or paper to explore an idea or explain it to a teammate. It may break the rules of the notation, and it is thrown away or photographed. This is by far the most common use.
  • As a blueprint. A detailed, precise model that is the design, from which code is written (by people or by tools). Heavy but sometimes justified in safety-critical systems or when a model is the contract between companies.
  • As documentation. A cleaned-up diagram kept next to the code to explain architecture. Keep these few and current, because a stale diagram misleads.

A useful rule: draw the least that answers the question, and keep it only as long as someone reads it. Text diagram tools (such as Mermaid and PlantUML) let you store diagrams as plain text in version control, so they can be reviewed and updated like code.

Common mistakes to avoid:

  • Modeling everything. A class diagram with 80 classes teaches nobody anything; split it by area.
  • Mixing levels of detail. Do not put method bodies on an overview diagram.
  • Drawing once and forgetting. A diagram that no longer matches the code is worse than none.
  • Treating the diagram as the goal. The goal is a shared understanding and a better design.

Reading any UML diagram

Whatever the type, a few habits make reading easier:

  1. Find the title and ask what question it answers.
  2. Identify the nodes (boxes, ovals, lifelines) and the edges (lines and arrows). Arrowheads carry meaning that differs between diagram types.
  3. Look for labels on edges and multiplicities such as 1 or *.
  4. Notice what is absent; every diagram hides detail.

One more stand-in shows the structural/behavioral split in action. It takes a list of diagram names and reports how balanced a design document is.

JS Is this design pack balanced?

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

No output.

The first pack has no behavioral view, so the review points out that nobody can see how the system works over time. The second has both families and raises no complaints. The third is balanced but long, so the review asks the maintenance question. These checks are simple heuristics; the aim is only to practice thinking about what a pack of diagrams does and does not cover.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which statement best describes UML?

    UML is a modeling notation. It does not run, and it does not prescribe how to organize a project.
  2. 2. Which diagram is structural?

    A deployment diagram shows which artifacts live on which nodes, which is structure. The others show behavior over time or goals.
  3. 3. Why is a diagram called a model?

    A model is a deliberate simplification. Choosing what to leave out is part of the skill.
  4. 4. What is a good first step when choosing a diagram?

    Start from the question. The question determines the diagram, not the other way around.

Summary

  • UML is a standard notation for describing software; it is a way of thinking and communicating, not a method or a language you run.
  • Structural diagrams show what the system is made of; behavioral diagrams show what it does over time.
  • Models simplify on purpose, so each diagram should answer one question for one audience.
  • Most use is informal sketching; keep formal or documented diagrams few, current and stored as text where possible.
  • Read any diagram by finding its question, nodes, edges, labels and what it omits.

Next: Use Case Diagrams.