Designer Interview - Car Booking System

A car reservation system is a very popular question in an interview with Software Development. I designed the following structure of the ER / OOP structure when I was asked about this:

The car class / table has a car identifier, type (compact, standard, etc.), model, model. The client has a client identifier, etc. Reservation is an associative table in which the car identifier No., user identifier and date for which the car is reserved are stored. For simplicity, we can assume that a car can be reserved only in pieces of days.

Here's the tricky part where I floundered - What happens when Client 1 reserves a compact car with Id Car 3 on July 27th. What happens if Car 3 is on July 24th. Other compact cars are available, but from July 24 to July 27 they are all taken. Therefore, when customer 1 arrives on July 27, he ultimately does not have a car.

The disadvantage that I think is that the car and the client are linked in the reservation table. Is there a better way to model these relationships, as well as regular use cases, such as finding an affordable car for a specific date, reserve it for that date, etc.

+6
source share
1 answer

You can add another boolean field to Car called Working . If Car 3 adds up, then

  • set Working to false .
  • Find it in Reservation .
  • if he is there, then find another car of this type in Car .
  • if found, replace this vehicle with another vehicle for Reservation .
  • another customer call.
+2
source

Source: https://habr.com/ru/post/921842/


All Articles