Quick Expense Manger. Your free expense manager. Lots of features. The application is also ad free.

Design a Parking Lot

Posted on Aug. 3, 2018
design-a-parking-lot

In this post I will discuss how to approach any design problem and we will design a parking lot for an example. When you are trying to approach a design problem, try to check out the nouns.

For the parking lot, we have the following nouns.

Parking Lot, Parking Space, Car

There can be also different types of parking spaces like - VIP Parking Space, Restricted Parking Space, Reserved Parking Space etc.

There can also be different types of Parking lots. Let's say Basement Parking Lot which is opened for a limited hours of the day.

Now let's take out the crucial points.

1) Parking lot has Parking Space.

2) Parking Space is either full or empty

3) There should be a Parking Lot manager which manages the parking lots. The user makes a request to the Parking lot manager requesting a parking space in a specific parking lot and the Parking Lot manager handles the request.

So, we have more or less the below interfaces.

IParkingLot
- isParkingSpaceAvailable()
- getEmptyParkingSpace()
- getAllRestrictedParkingSpace()

IParkingSpace
- isEmpty()
- isRestricted()

IParkingLotManager
- getParkingSpace(IParkingLot parkingLot,String carNo)
- freeParkingSpace(String carNo)

and below classes

ParkingLot
- List<ParkingSpace> parkingSpaces
- boolean isFull
- String opensAt
- String closesAt

ParkingSpace
- boolean isOccupied
- isRestricted
- isReserved

ParkingLotManager
- List<ParkingLot> parkingLots;
- Map<String,IParkingSpace> carNoToParkingSpaceMap

This is the basic skeleton of our design. We can now add many more things to the above design. We can have different parking lots which implements our IParkingLot interface.


For example we can have a PrivilegedParkingLot for which you need specific privilege to park your car there. We can add one more attribute "isPrivileged" to the to our PrivilegedParkingLot class and do some more verification when we override the getParkingSpace() method to check if the specific car has the privilege to park there.


This is more than enough to impress any interviewer. Once your basic model is ready, you can add any number of features you want to add. The interviewer is interested in Object orientedness of your design.


You can use this approach in any design problem (For example - Design Snake and Ladder game) that you have. Just check out the physical objects and there would be a virtual object like the ParkingLotManager in this case.

Just to give some pointers for the Snake and Ladder game design, here are the Objects that you have more or less.

Snake, Ladder, Board, Square, Players, Dice and the Virtual object Game. Just use the same approach I have discussed above and try to apply that to this design problem.

Sharing is Caring!

Quick Expense Manger. Your free expense manager. Lots of features. The application is also ad free.

GET FREE UPDATES


RECOMMENDED POSTS FOR YOU


profile image

Kaushik Baruah


ABOUT

My name is Kaushik Baruah and I am the chief blogger on this Blog. I have developed this Blog from scratch using Django as the backend and here I like to share my experience as software engineer and research engineer with my online readers. I will try to focus on career planning, latest emerging technologies and tutorials on various computer science subjects. You can follow me on Twitter, Facebook and Google+

GET FREE UPDATES

POPULAR POSTS

Copyright © 2018
About Us

My name is Kaushik Baruah and I am the chief blogger on this Blog. I have developed this Blog from scratch using Django as the backend and here I like to share my experience as software engineer and research engineer with my online readers. I will try to focus on career planning, latest emerging technologies and tutorials on various computer science subjects.

Get Free Updates