intro practice · system design prompt
Pluggable pricing strategies
Design a checkout system where pricing strategy is swappable: flat, percentage-off, BOGO, member-tier. Each strategy is a class with the same price(cart) signature.
The mechanism
The strategy pattern lets you swap an algorithm at runtime by hiding it behind a common interface. The caller does not know (or care) which version is used. Reach for it when "the same operation has many implementations" — pricing rules, sort orders, routing strategies.
Expected evidence
Interface + 4 concrete strategies + how the cart picks one at runtime.
Try this drill in the practice workspace →
Hints when you need them
- Inject the strategy; do not let cart code know its type.
- Compose strategies for stacked discounts.