Requirements
- Parking lot has parking spots.
- Parking lot should check available spots per floor, and should display on the screen at the entrance.
- Driver can freely choose where to park.
- Spots have its type, like for small vehicles, standard, heavy, and for handicapped.
- Each spot has different cost type.
- The cost on the car starts right after the car enters the parking lot.
- All cars should pay when they try to go out to exit.
Define Core Objects
- Spot - Spot abstract class. All classes are spot types.
- Vehicle - Abstract class for cars which entered into parking lot. Children implementations are "type" of the vechicle.
Two abstract classes above are core objects to show the relation between spot and vehicle.
- FloorManager - responsible for managing which spots are available, allocated, and etc. at the certain floor. FloorManager manages cars to park or unpark to designated spot.
- ParkingLotService - manages whole parking lot. It has responsible for managing each floor via FloorManager class,
Analyze Relationships
If a vehicle parks it requires Spot, while Spot can be instantiated stand alone.
If a vehicle does not park, just roaming around to locate parking spot, Spot can be null.
ParkingLotService is the top manager service of managing all floors, spots, and entered vehicles.
FloorManager will be instantiated per each floor, from ParkingLotService, and will be injected to ParkingLotService.
Spot will be instantiated per each spots on specific floor, from FloorManager, and will be injected to FloorManager.
Establish Hierarchy
Refer to diagram
Design Patterns
- composite pattern for structuring hierarchical classes like ParkingLotService, FloorManager
- Singleton pattern for ParkingLotService since it is the main center class to manage all floors and spots of the parking lot.
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
Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...
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...