CSE Roadmap

Core tier · about 2 hours · 7 parts

Part 5 of 7 · 1 min read

The sequence diagram

Who calls whom, in order.

A class diagram shows structure. A sequence diagram shows one request over time. Each object has a vertical line. Arrows run between lines, from top to bottom, in call order.

For book(room, user, slot):

User        BookingService       Booking        Room
 |  book(...)     |                  |             |
 |--------------->|                  |             |
 |                | for each active booking in room
 |                |  overlaps(slot)? |             |
 |                | no overlap found |             |
 |                | new Booking(...) |             |
 |                |----------------->|             |
 |                |   booking        |             |
 |<---------------|                  |             |

Reading it: the user asks the service. The service checks every active booking of that room for overlap. If none overlaps, it creates a booking and returns it. A failing path would show an arrow back with an error instead.

Draw a sequence diagram for the one or two flows that matter most. Interviewers use it to check that the methods in the class boxes really fit together.

Sequence diagram

A sequence diagram shows the calls between objects for one scenario, in the order they happen.

Example: the steps of book(...), from the user's call to the returned booking.

Check yourself: 1. What does time do on a sequence diagram? 2. Which object runs the overlap check? 3. How would the failure path look?