Wednesday, March 3, 2010

Design a Restaurant reservation system

It's a OO design question where you have to design a Restaurant reservation system. You have to tell about the classes, data members and interfaces and how they will interact with each other.

For these kind of problems - first define all the entities in the ecosystem for this application and the assumptions you are going to make.

Define the problem -
  1. In a restaurant, there are multiple tables with varying seating capacities.
  2. A table of a seating capacity of n can be booked for m people of a group such that m <= n
  3. A table can be re-booked for the same day only if the there is a minimum T duration difference between 2 bookings.
  4. Booking can be done in fixed hours when the restaurant operates.
External interface inputs-
  1. Number of people [input]
  2. Time of booking required [input]
  3. Contact details [input (optional)]
External interface Methods
  1. int CheckTableAvailability(int NumPeople, time_t TimeOfBooking, int *tableNumber, time_t *alternativeTime) - This function will tell whether the booking is possible or not. If possible on the input time it will return 1 and file the tableNumber. If not on the input time, but at some time near to that, it will return 2 with the alternativeTime and TableNumber that can be booked. If not at all possible then it will return 0.
  2. bookTable(contactDetails, tableNumber, time_t TimeOfBooking)
Extra functionality
for CheckTableAvailability , it can also return an array of tableNumber possible for booking. Like some restaurants have different sections (smoking zone, pool side, garden side etc) which will give the customer a choice to make.

Class: Table
{
int TableId;
int SeatingCapacity;
string speciality;
}

Class Booking
{
int bookingId;
int TableId;
time_t startTime;
customerDetails;
}

Class: BookedTables
{
HashTable bookings ( key: timeslot, value: int booked[NumTables] )

My First Post

In these posts I will tell about the questions which are generally asked in interviews for Dev position. I will also try to give solutions.