Design an airline reservation system. Customers search flights by route and date, pick seats, pay and receive a ticket. The airline manages aircraft, crew and schedules.
A **flight** runs on a route with a departure time on an **aircraft** with seats.
Customers **search** by origin, destination and date.
A booking reserves **seats** for one or more **passengers**.
Seats are **economy or business** with different prices.
A booking can be **cancelled** or **changed**, with a rule-based fee.
Stage 1: Aircraft, flights and seats
Name the physical things.
Seats must belong to a flight's aircraft, or two flights share one seat map. An `Aircraft` owns its seats and a `Flight` uses one aircraft on a route and time. Seat availability is then per flight, not global. Each flight needs its own taken/free state, even though the layout comes from the aircraft.
Stage 2: Bookings and holding seats
Reserve seats for passengers.
Two customers can pick the same seat at once. `BookingService.hold` marks the seats held for the flight in one atomic step and creates a `Booking`. `confirm` turns it into a ticket after payment. The check and the hold happen together, so the second customer sees the seat taken. Holds need a timeout, or abandoned checkouts block seats.
Stage 3: Fares and fees: Strategy
Make pricing and cancellation rules swappable.
Prices rise near departure and fees depend on how close the cancellation is. A `FarePolicy` with `price` and `cancelFee`. `DynamicFare` raises the price as seats fill and departure nears. Pricing is separate from booking, so a promotion is a new policy (**Strategy**). Store the price paid on the booking so later changes do not alter it.
Stage 4: Booking states and alerts
Allow only legal moves and tell passengers of changes.
A held booking should expire and a flown one cannot be cancelled. Passengers are not told about delays. `BookingState` with `HeldState` (confirm or cancel) and `ConfirmedState` (cancel with fee). `FlightAlert` finds the bookings on a flight and notifies them of delays. Each state allows only its own actions (**State**), and alerts reach exactly the affected passengers. Cancelled and flown states follow the same shape and are left out for space.