Object Oriented Design Interview Question: Design a Car Parking Lot.

Most interviews at top tech companies, especially Amazon, involve the design of an object oriented system, like an object oriented parking lot or an elevator system. A simple intuition about the similarity between object oriented systems and their real-world counterparts can help you blow away these questions with ease.
Object oriented systems communicate a lot like we humans do in our everyday lives.
When you go to a restaurant, you interact with the server, hostess and so on. They are human beings too like you, but just with some specialized/over-ridden behaviors such as their job type (**inheritance). **You can view them as sub-classes of humans — after all outside of their work, they don’t take orders and they too go to movies, visit a doctor, and are just normal human beings. (**polymorphism).**
How do you communicate with the server? It typically falls into one of these three categories, getting you seated, taking your order, and serving you food. Of course, servers do other things too, like telling the chef about your order, but you don’t get to see these things. Your interaction with the server is just restricted to these three behaviors (**data abstraction).**
Now, here are some steps to follow to answer an object oriented design question like design an object oriented parking lot.
1. Identify the major entities like vehicles, parking spaces, parking structure and so on using interfaces.
2. Identify specialized subtypes of these entities using abstract classes or just regular classes. For example, your parking spaces may be of different types, two wheeler parking spots, car parking spots, handicapped parking spots and so on.
3. Determine the functionality(behavior) of each of these entities, such as a a car should have a license plate, and have the ability to move; a parking structure should be able to tell you the next available spot to park; a parking space should be able to keep track of your cost of parking and so on.
4. Determine the functionality of specialized entities. All parking spaces have same properties like indicating whether they are occupied or not, and calculating the cost of parking your vehicle but two wheeler spots are cheaper than four wheeler spots.
5. Setup relationships between entities that communicate with each other. Parking space and parking structure can be connected association, that is a parking structure has many parking spaces, and of different types.
6. Lastly, to make yourself standout, use design patterns where appropriate. The most obvious scenario is, obviously not everyone should be able to create their own parking structure on the fly. Make it a singleton class so there is only parking structure, and vehicle owners will use it using your public methods.
In the video, I follow the above steps to design an object oriented parking lot. You will also see when to use interfaces vs abstract class, the different use cases of interfaces, a practical programming example of interface (instead of the car inherits vehicle that you read in books) and a few more design patterns that will make you stand out.

visit www.programminginterviewprep.com

source