Designbench

Lesson 7.3 · 20 min

UML diagrams

Click an arrow to see the Java behind it (or the Java to see the arrow), step through a parking-lot exit with an alt box for a declined card, and drive an order through a state diagram that rejects invalid events.

The idea in plain words

UML is a standard way to sketch software with boxes and arrows, so another engineer can read your design at a glance. In interviews, a quick class diagram and one sequence diagram say more than minutes of talking.

The problem it solves

Explaining a design in words takes long and is easy to misunderstand. A shared drawing notation lets you show structure and flow in seconds, as long as everyone reads the arrows the same way.

How it works

  1. A class diagram shows classes as boxes with their fields and methods, and lines for how they relate.
  2. Arrow styles mean specific things: inherits, implements, owns, uses.
  3. A sequence diagram shows who calls whom, in time order, from top to bottom.
  4. A state diagram shows the states an object moves through and what moves it.
  5. In interviews, draw only what the discussion needs.

Example

A Car “has” an Engine that is destroyed with it: composition, a filled diamond on the Car side. A Team “has” Players who exist without the team: aggregation, a hollow diamond. Mixing them up tells the interviewer something different from what you meant.

Key terms

Class diagram
Boxes for classes with their fields and methods, and lines for how they relate.
Sequence diagram
Who calls whom, in time order, top to bottom.
State diagram
The states an object can be in and what moves it between them.
Composition vs aggregation
Composition: the part dies with the whole (filled diamond). Aggregation: the part can live on its own (hollow diamond).
Multiplicity
How many objects take part: 1, 0..1 or *.

In this lesson you'll learn

Sections

  1. Theory: which diagrams
  2. Theory: class diagrams
  3. Theory: sequence
  4. Theory: state
  5. Theory: whiteboard tips
  6. Design: draw it right
  7. Check yourself

Cheat sheet

Owns, creates partscomposition ◆
Groups, doesn't ownaggregation ◇
extends / implements▷ solid / ▷ dashed
Uses in a calldependency, dashed →
if/else in a flowalt fragment

The interactive simulations and the quiz load with JavaScript.