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
- A class diagram shows classes as boxes with their fields and methods, and lines for how they relate.
- Arrow styles mean specific things: inherits, implements, owns, uses.
- A sequence diagram shows who calls whom, in time order, from top to bottom.
- A state diagram shows the states an object moves through and what moves it.
- 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
- Which UML diagrams matter in an interview, and what each is for.
- The six class-diagram relationships, linked both ways to the Java that produces them.
- How to draw a sequence diagram with an alt fragment and a state diagram for a lifecycle, quickly and clearly.
Sections
- Theory: which diagrams
- Theory: class diagrams
- Theory: sequence
- Theory: state
- Theory: whiteboard tips
- Design: draw it right
- Check yourself
Cheat sheet
| Owns, creates parts | composition ◆ |
|---|---|
| Groups, doesn't own | aggregation ◇ |
| extends / implements | ▷ solid / ▷ dashed |
| Uses in a call | dependency, dashed → |
| if/else in a flow | alt fragment |
The interactive simulations and the quiz load with JavaScript.