Design Parking Lot
Step 1: Handle ambiguity and clarify your assumptions
- How big is the parking lot?
- Is this a single or multiple level parking lot?
- What are the types of vehicles?
- What kind of spots do we have?
- Which cars can park in which spots?
Step 2: Outline use cases and constraints
- The parking lot has multiple levels. Each level has multiple rows of spots.
- The parking lot can park motorcycles, cars, and buses.
- The parking lot has motorcycle spots, compact spots, and large spots.
- A motorcycle can park in any spot.
- A car can park in either a single compact spot or a single large spot.
- A bus can park in five large spots that are consecutive and within the same row. It cannot park in small spots.
Step 3:
Draw core objects
- We use Parking Slot class to represent the parking space
- We use Vehicle class to represent cars
- We need a parking lot class as the manage object
- Because the parking lot is multilevel, we can use a level class to represent it
Analyze the relationships and draw high level design
- Each parking space will have a reference to the vehicle
- Each level will have many parking slots, we
- The parking lot will have multiple level objects