Skip to content
Knowledge Hub

Matching: pick a design pattern for each situation Basic

Estimated reading time: 1 min read

The hard part of design patterns is not memorizing class diagrams, it is recognizing the situation. Drag a pattern onto each situation.

Mistakes are fine: each time you miss, the game explains why that pattern is close but not right. The most commonly confused pairs are Strategy vs Factory, and Adapter vs Facade.

Matching

Which pattern does this situation need?

Each situation below comes from real backend code. Drag the best-fitting pattern onto each situation. A pattern can be used for several situations.

Tip: ask "what is changing?" before asking "which pattern?".

Tap Choose answer on each case. On a computer you can drag a card below onto a case.

Solved 0/8 · 0 mistakes

1Shipping fees are calculated differently for GHN, GHTK and the in-house delivery team. Which carrier an order uses is only known at runtime. Right now it is a 200-line switch.

2Your code calls Notifier.send(to, message). The newly purchased SMS SDK has the API client.messages.create({ phoneNumber, content, brandName }) and throws its own kind of errors.

interface Notifier {
  send(to: string, message: string): Promise<void>;
}

3PriceService.getPrice() is slow. You need to add caching, timing logs and retries, but you do not want to modify PriceService, and some places need the uncached version.

4When an order is paid: send an email, add loyalty points, notify the warehouse, fire analytics. Every quarter another team wants to add something. OrderService currently calls all 4 directly.

5Config has PAYMENT_PROVIDER=momo|vnpay|stripe. Each provider needs its client initialized differently (keys, endpoint, timeout). This logic is duplicated in 3 places.

6The checkout controller has to call stock, price, voucher, payment, shipping in the right order and handle errors at each step. 3 controllers (web, mobile, admin) repeat this block.

7The domain calls FileStorage.put(key, stream). The company moves from AWS S3 to Google Cloud Storage. The GCS SDK has completely different function names, error types and stream upload style.

8Marketing has percentage discounts, fixed-amount discounts, buy 2 get 1, and flat-price deals. Every month brings a new kind. Each voucher stores a type in the database.