intro practice · system design prompt
Coffee-shop order decorator
Model a coffee order with milk / sugar / whip add-ons via the decorator pattern. cost() and description() should compose automatically.
The mechanism
The decorator pattern wraps an object in another object with the same interface, adding behavior without subclassing. It shines when feature combinations explode — instead of one class per combination, you stack small decorators.
Expected evidence
Base Beverage + 3 decorators, plus a sample order chain and its computed cost.
Try this drill in the practice workspace →
Hints when you need them
- Each decorator wraps a Beverage and is itself a Beverage.
- Order of wrapping matters for description, not cost.