LLD Capstones
Small systems to redesign end to end, in the style of machine-coding rounds.
Low-level design capstones give you a working but tangled system, such as a parking lot, an elevator or an expense splitter, and ask you to redesign it. There is no single right pattern; several ideas from the other categories have to work together.
A good approach is to name the things in the system and what changes about each of them: rules that vary become strategies, lifecycles become states, notifications become observers, and the main class goes back to coordinating rather than doing everything.
You'll recognise it when
- One class with many maps holding parallel pieces of data.
- Status strings and booleans steering most methods.
- Pricing, allocation or scheduling rules chosen by flags.
- New variants of the system require copying the main class.
Example
A coffee kiosk takes orders and calls out names when drinks are ready. Here is how to start a redesign.
class Kiosk {
Map<Integer, String> drinkByOrder = new HashMap<>();
Map<Integer, String> statusByOrder = new HashMap<>(); // "NEW", "BREWING", "READY"
Map<Integer, String> nameByOrder = new HashMap<>();
void tick() {
for (int id : statusByOrder.keySet()) {
if (statusByOrder.get(id).equals("BREWING") && brewed(id)) {
statusByOrder.put(id, "READY");
speaker.say(nameByOrder.get(id) + ", your " + drinkByOrder.get(id) + " is ready");
}
}
}
}class Order {
private final String customer;
private final Drink drink;
private OrderStatus status = OrderStatus.NEW;
void markReady(List<OrderListener> listeners) {
status = status.moveTo(OrderStatus.READY);
listeners.forEach(l -> l.ready(this));
}
}
class Speaker implements OrderListener {
public void ready(Order o) { say(o.customer() + ", your " + o.drink() + " is ready"); }
}Why it's better: Data that belongs together lives in one object, status changes go through one checked transition, and new reactions (a screen, an SMS) are new listeners rather than edits to the kiosk loop.
Ideas you'll practise
Problems 9
- LD-01The Messy Parking LotL4HardComing soon
- LD-02Elevator Controller SpaghettiL4HardComing soon
- LD-03Splitwise Settlement MessL4HardComing soon
- LD-05Hardcoded Snake and Ladder BoardL4MediumComing soon
- LD-06Rate Limiter If-LadderL4HardComing soon
- LD-07Library Management God ClassL4MediumComing soon
- LD-11Home-Grown Logging FrameworkL4MediumComing soon
- LD-12Cache With Eviction PoliciesL4MediumComing soon
- LD-13Wallet Paying Through Many GatewaysL4HardComing soon