Requirements
Functional:
1. Assign nearest spot across the floors from the entrance
2. Add to waiting list if there are no empty spots available for the incoming Vehicle size
3. If the waiting list is full, do not accept new vehicles
4. Calculate and collect fee at the checkout based on hours.
5. There should be a time limit for parking window, we could have a warning system before towing.
Non-functional:
1. New vehicle sizes could be added without affecting the rest of the system
2. New spots could be added without affecting the rest of the system
3. New payment methods could be added without affecting the rest of the system
4. Fee calculation strategy could be changed without affecting the rest of the system
Define Core Objects
vehicle, spot, lot, floor, entrance
onboardingController, spotController
graph, minHeap, availableSpots
nearestspotCalulator, distanceCalulator, distanceCalulatorStrategy, announcingSystem, feeCalculator, paymentProcessor, paymentStrategy
Analyze Relationships
Vehicle has a spot (1-1)
Lot contains spots (1-many)
Spot contains Floor (many-1)
Floor contains Entrance (1-many)
Lot contains spotController (1-1)
Lot contains floorController (1-1)
Lot conatins entrance (1-1)
Lot contains onboardingController (1-1)
onboardingController contains floorController (1-1)
onboardingController contains spotController (1-1)
Lot contains graph (1-1), minHeap for each size (1-1), availableSpots (1-1) // Graph is formed with spots, corners, elevators as nodes
Lot contains nearestspotCalulator (1-1)
nearestspotCalulator contains distanceCalulator (1-1)
distanceCalulator contains distanceCalulatorStrategy (1-1)
floorController and spotController notifies Lot to update graph, minHeap, availableSpots using distanceCalulator
Lot contains VehicleFactory (1-1)
Lot contains SpotFactory (1-1)
VehicleFactory returns Vehicle
SpotFactory return Spot
Lot contains orderProcessor (1-1)
Lot contains announcingSystem (1-1)
Lot contains feeCalculator (1-1)
feeCalculatorStrategies of multiple sizes are inherited from feeCalculatorStrategy
feeCalculator has a calculateFee method that takes input as size and calls calculateFee method of appropriate strategy
paymentStrategies of different payment types are inherited from paymentStrategy
orderProcessor has a processPayment method that takes input as paymentType, amount and calls processPayment method of appropriate strategy
Establish Hierarchy
Vehicles of multiple sizes are inherited from Vehicle
Spots of multiple sizes are inherited from Spot
feeCalculatorStrategies of multiple sizes are inherited from feeCalculatorStrategy
paymentStrategies of different payment type are inherited from paymentStrategy
DijkstrasDistanceCalulatorStrategy implements distanceCalulatorStrategy
Design Patterns
VehicleFactory creates Vehicle object by size
SpotFactory creates Spot object by size
Stretgy - feeCalculatorStrategies of multiple sizes are inherited from feeCalculatorStrategy which are used in feeCalculator
Stretgy - paymentStrategies of different payment type are inherited from paymentStrategy which are used in orderProcessor
All the 1-1 mappings from Lot and their 1-1 associations and Lot itself are singletons.
Strategies of a size are singletons, we can store them in client class's map or a strategy manager.
Observer pattern to notify to Lot to update graph, minHeap and availableSpots when spots or floors are added.
Observer pattern to notify to Lot to update minHeap and availableSpots when spots are released.
Define Class Members (write code)
Attributes: For each class, define the attributes (data) it will hold...
Methods: Define the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.
public class Car { ... } // ExampleAdhere to SOLID Guidelines
Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...
Consider Scalability and Flexibility
Floors can be added without disturbing the remaining system, same for Spots, Vehicle Sizes, Payment Types, Distance Calculation strategy, fee calculation strategy
Create/Explain your diagram(s)
Try creating a class, flow, state and/or sequence diagram using the diagramming tool. Mermaid flow diagrams can be used to represent system use cases. You can ask the interviewer bot to create a starter diagram if unfamiliar with the tool. Briefly explain your diagrams if necessary...
Future improvements
Critically examine your design for any flaws or areas for future improvement...