Car Rental System: low-level design

Design a car rental system. Customers search for available cars, reserve one for a date range, pick it up, return it and pay based on the rental period and any extras.

Stage 1: Vehicles, branches and customers

Name the things.

We need to know which cars exist and where. `Vehicle` has a type and plate, and a `Branch` owns its fleet and can list cars free for a date range. Availability is a question about dates, so it takes a range and not a flag. Scanning the fleet is fine for hundreds of cars per branch.

Stage 2: Reservations and the service

Book a car for a date range.

Nobody guards against two customers booking the same car and dates. `Reservation` records the car, customer and dates. `RentalService.reserve` checks the car's existing reservations for overlap and saves the new one in the same locked step. The check and the write happen together, so two requests cannot both win. Lock per vehicle, not for the whole service, so unrelated cars do not wait.

Stage 3: Pricing: Strategy

Make the price rule swappable.

Weekend rates and long-rental discounts keep arriving. A `PricingStrategy` with `quote`. `DailyPricing` implements it; other rules are new classes. Pricing changes never touch reservation code (**Strategy**). Quotes must be stored on the reservation so a later rate change does not alter an existing booking.

Stage 4: Extras: Decorator

Add insurance and child seats without changing the base.

Each extra changes the total and combinations multiply. A `PriceItem` with `cost()`. `BasePrice` is the rental, and each extra wraps another `PriceItem` and adds its cost. `Payment` records the final amount. Any mix of extras works by wrapping (**Decorator**), with no subclass per combination. Long wrapper chains are hard to debug; log the itemised list from the chain for the receipt.