How do you decide which design pattern to use for a new feature?
Answer it out loud before you open anything. The value of the flags below is in comparing them to what you actually said — including whether you named a cost, or only a principle.
A team is building a notification system that must send email now and, according to the product manager, "probably Slack and SMS at some point". The tech lead has proposed a design document listing Factory, Strategy, Observer and Template Method. No code exists yet.
React to this
Say what you would change, what you would leave alone, and what you would need to know first.
The tech lead has already written this:
```ts
interface NotificationStrategy { send(user: User, message: string): Promise<void> }
class EmailStrategy implements NotificationStrategy { /* ... */ }
class NotificationStrategyFactory {
static create(kind: string): NotificationStrategy {
switch (kind) { case 'email': return new EmailStrategy() }
throw new Error('unknown')
}
}
class NotificationObserver { /* subscribes to a bus that has one publisher */ }
```
What would you say in review, and what would you propose instead?What it is really testing
Whether the candidate reverses the question. The correct first move is to ask what problem exists, because a pattern is a response to an observed problem and choosing one first inverts the causality. Candidates who start naming patterns have told you how they design.