Design a restaurant management system. Guests are seated at tables, waiters take orders from a menu, the kitchen prepares them, and the table gets a bill with tax and a discount.
A **menu** has items with prices and categories.
**Tables** have a capacity; the host seats a party at a free table that fits.
A waiter takes an **order** (items with notes) for a table, and more items can be added later.
The **kitchen** sees order items and marks them **preparing, ready, served**.
The **bill** adds tax and an optional discount; tables can be **split** between guests.
Stage 1: Menu, tables and seating
Name the things and seat a party.
We need a menu and a way to put a party at a table. `Menu` lists items, and `Host.seat` finds the smallest free table that fits the party. Picking the smallest fitting table leaves bigger ones for bigger parties. Smallest-fit is a simple policy; a smarter one (merge tables) is a later addition.
Stage 2: Orders and lines
Take an order that can grow.
A table orders more over time, and each dish is cooked separately. An `Order` owns `OrderLine`s. Each line is one dish with a quantity, a note and its own status. Status per line lets the starter be served while the main is cooking. More lines are added to an open order. Closing the order freezes them for the bill.
Stage 3: The kitchen and line status
Cook each line and track it.
Nothing tells the kitchen about new items or stops a line jumping from placed to served. `Kitchen` receives each new line and marks it ready. `LineStatus` has a fixed order and `advance()` only moves one step forward. Status moves in one direction, so the kitchen and waiter never disagree. A line cancelled while preparing needs an extra CANCELLED path. Decide the rule with the restaurant.
Stage 4: Billing and discounts, with events
Add tax, discounts and tell the right people.
The bill ignores tax and discounts, and the kitchen is not told about new items. `Bill` totals the order, adds tax and applies a `DiscountRule`. `Order` calls its `OrderListener`s when a line is added or ready, so the kitchen and the waiter's screen update themselves. Discounts are swappable (**Strategy**) and the kitchen is reached by events (**Observer**), not by the order calling it. Round once at the end of the bill, not per line, or the total drifts by a few paise.