Sequence Diagram
A sequence diagram orders messages between participants over time. Lifelines identify collaborators; calls and replies show how a use case crosses responsibility boundaries.
What you’ll understand
- A sequence diagram orders messages between participants over time. Lifelines identify collaborators; calls and replies show how a use case crosses responsibility boundaries.
- Follow ShippingClient to ShippingAdapter to LegacyShipping, then follow the normalized result back to the client.
- Evaluate the tradeoff: A sequence is one scenario, not every possible execution. State its inputs and distinguish a normal response from a failure or alternate branch.
Useful first: Classes and Objects
The idea and when to recognize it
A sequence diagram orders messages between participants over time. Lifelines identify collaborators; calls and replies show how a use case crosses responsibility boundaries.
- Requirement: A shipping client obtains a quote from a vendor with incompatible units.
- Change to anticipate: Show the request translation and reply normalization in their actual order.
- Design goal: Follow ShippingClient to ShippingAdapter to LegacyShipping, then follow the normalized result back to the client.
Start with the concrete problem
A shipping client obtains a quote from a vendor with incompatible units.
Show the request translation and reply normalization in their actual order.
| Direct implementation | Revised design |
|---|---|
| Omitting the reply conversion makes the diagram claim that vendor hours already satisfy a day-based client contract. | Follow ShippingClient to ShippingAdapter to LegacyShipping, then follow the normalized result back to the client. |
| The baseline case can hide the problem. Compare the extension and boundary fixtures before accepting this design. | A sequence is one scenario, not every possible execution. State its inputs and distinguish a normal response from a failure or alternate branch. |
Responsibilities and contracts
Follow ShippingClient to ShippingAdapter to LegacyShipping, then follow the normalized result back to the client.
- ShippingClient: Depends only on the normalized quote contract. Public operations: quote(order)
- ShippingAdapter: Translates the shipping contract. Public operations: quote(order)
- LegacyShipping: Owns the vendor API. Public operations: estimate(grams, hours)
Read the design
Select a participant to inspect its responsibility and public operations. Follow the labeled relationships; an arrow indicates direction, while the legend distinguishes ownership, substitution, and temporary use.
Preparing the design walkthrough…
Follow the interaction
Choose a supplied workload and compare the direct and revised implementations. Step through the same operation in both languages. Object values are recorded after each highlighted statement; previous steps remain unchanged.
Preparing the design walkthrough…
Implementation and expected output
Read the complete example alongside its input and expected output. The implementation selector changes the displayed program; the language selector preserves your current scenario and playback position.
Preparing the design walkthrough…
Try the idea in another setting
A password-reset sequence can show token issuance, email delivery, and later verification without revealing implementation secrets.
- Name the new client contract before adapting the example.
- Identify which state belongs to each object and who controls its lifetime.
- Write one normal case and one boundary case before extending the design.
Tradeoffs and interview takeaways
A sequence is one scenario, not every possible execution. State its inputs and distinguish a normal response from a failure or alternate branch.
Common mistake: Omitting the reply conversion makes the diagram claim that vendor hours already satisfy a day-based client contract.
- Explain the choice: Follow ShippingClient to ShippingAdapter to LegacyShipping, then follow the normalized result back to the client.
- Challenge your choice: A sequence is one scenario, not every possible execution. State its inputs and distinguish a normal response from a failure or alternate branch.
- Describe a requirement that would make the simpler implementation sufficient.
Design challenge and knowledge check
Preparing the design walkthrough…