Preparing your design workspace

Loading the problem and your saved attempt…

Design a Car Rental System with Design Patterns

Model a car rental flow whose pricing rules, car states and notifications can change without rewriting the booking code.

For this exercise, assume a car rental company with a few branches wants the core of its booking software redesigned so it is easy to change. Each car belongs to one branch and one category (economy, SUV, or van).

A customer searches a branch for categories that have a free car on chosen dates, books one (the system assigns a free car of that category), picks the car up, and returns it later. A customer can also cancel a booking before pick-up, which frees the car.

Each car is in exactly one state at a time: available, booked, rented out, or in maintenance.

Only some moves are allowed: an available car can be booked or sent to maintenance; a booked car can be picked up or freed by a cancellation; a rented car can only be returned, which makes it available again; a car in maintenance can only be marked repaired.

Any other request, such as picking up a car that is in maintenance or already rented out, is refused and changes nothing.

The price of a rental depends on the category and the number of days, and the company changes its pricing rules often (weekend rates, long-rental discounts, seasonal prices) without wanting to edit the booking code. Customers are told by email or text message when a booking is confirmed and when the car is returned.

Design the objects, their responsibilities, the interfaces, and the interactions, and say which design patterns, if any, help keep the design easy to change and why. No code is needed. One follow-up adds a new category of car. Payments, insurance, loyalty points, a user interface, and storing data are out of scope.

Everything runs on one thread.