A Five-Question Checklist for Explaining Design Patterns
Explain the invariant and the behavior that varies.
Five questions that turn a design-pattern name into an interview answer another engineer can check and test.
At a glance
- Start with the rule that must always hold, then name the pattern that protects it.
- Say what varies: interchangeable calculations point to Strategy; behavior that depends on a lifecycle stage points to State.
- Required ordering, such as "store before billing", belongs in one explicit workflow, not in the order subscribers happen to run.
- Walk through one failure: a timeout does not prove the first attempt had no effect.
- Offer the smallest design that works. Extra indirection must earn its place.
The five questions
| Question | What a strong answer says |
|---|---|
| 1. What must always be true? | One invariant in plain words: "a discount never makes the total negative". |
| 2. What actually varies? | Interchangeable calculations, or the legal actions in each lifecycle stage. Two stable branches may only need an if. |
| 3. Who owns the dependency? | Which component chooses the next step, and which one owns each local rule. |
| 4. What happens when a boundary fails? | One exception, one slow dependency, one duplicate request: what is retried safely, and how the user learns the result. |
| 5. What is the smallest design that meets the need? | The proposal against a direct call or a small service, and what evidence would make you simplify it later. |
Independent reactions or a required workflow?
| Independent reactions | Required workflow | |
|---|---|---|
| Example | a chart and a log panel both react to a new reading | a reading must be stored before an invoice is created |
| Fits | Observer: subscribers register and receive notifications | one owner that runs the steps in order |
| Ordering | no subscriber depends on another | explicit, with a failure policy for each step |
| Lifetime | each screen removes its subscription when it closes | if it must survive a crash, store its progress so it can resume or stop |
A good answer names both relationships and the point where they differ.
A worked answer
A dashboard shows a temperature chart and a logging panel. Both react to the same updates on their own, so a subscription-based design is reasonable, and each screen owns its subscription. Then a rule arrives: a reading must be stored before an invoice is created. That dependency goes into a workflow with an explicit failure policy. It must not depend on the order in which two panels registered.
Name the tests too:
- Closing a screen removes its subscription.
- A failed store step means no invoice is created.
- Retrying a completed operation does not create a second invoice.
Common mistakes
- Naming a pattern first: state the invariant, then the pattern that protects it.
- Treating every
ifas a missing Strategy: two stable branches can stay a conditional. - Hiding required order in subscriber registration: give the workflow one owner.
- Treating a timeout as "nothing happened": decide whether a repeat is safe, and use an identifier for the same logical work.
- Forgetting lifetime: a long-lived publisher that holds an ordinary (strong) reference, such as a C# event, keeps a subscriber reachable until it unsubscribes or is removed.
In an interview
How do you explain a design pattern in an interview? Start with the rule it protects and what varies. Then name the pattern, the owner of each decision, one failure and how you would test it.
Strategy or State: how do you choose? Strategy when interchangeable calculations sit behind one contract, such as shipping prices. State when the allowed actions depend on where the object is in its lifecycle, such as a dispatched order.
When is Observer the wrong choice? When one step must finish before another starts. Observer suits independent reactions; required ordering needs an explicit workflow.
Is retrying after a timeout safe? Only if the operation is idempotent, or the server enforces an idempotency key: it recognizes the repeat and returns the first result without doing the work again. The first attempt may have succeeded even though its response was lost.
When would you remove a pattern? When it adds indirection without making a real variation or dependency easier to understand, test or change.
Check yourself
A chart and a log panel both react to each new sensor reading, and neither depends on the other. Which design fits best?
Show answer
Correct answer: B
Independent reactions to the same event are what Observer is for; each panel owns its subscription.
Option A: A fixed order adds coupling that independent panels do not need.
Option C: Strategy selects one interchangeable algorithm; it does not notify several independent subscribers.
Option D: The panels have no lifecycle rules that limit what they may do.
A reading must be stored before an invoice is created. Where should that order live?
Show answer
Correct answer: B
A required order needs one owner that runs the steps and decides what happens when one fails.
Option A: Registration order is incidental and easy to break.
Option C: Retrying does not make the store step happen first.
Option D: A display panel should not own a billing rule.
A payment call times out. What does the timeout tell you about the first attempt?
Show answer
Correct answer: B
The server may have processed the request and lost only the response, so a repeat is safe only if the operation is idempotent, or the server enforces an idempotency key and returns the first result.
Option A: A lost response looks the same as a failed request.
Option C: A timeout on the client does not undo work on the server.
Option D: The request may have arrived and been processed.
Sources
- Observer design pattern: providers, observers, and unsubscribing through
IDisposable. - Retry pattern: transient faults, and why a non-idempotent operation may run twice.
- Domain events: design and implementation: side effects of a change made explicit.
Practice
Apply the five questions to the Observer and Mediator lessons of the Design Patterns in C# course, then to the Observer or Mediator? design workbook. The Observer, Mediator, Chain of Responsibility and Visitor lesson practice has 8 questions on those four patterns: write your answer before checking each one.
TechInterviewNotes Editorial Team · Updated 28 Nov 2026 ·