Requirements
Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.
Check Spot Availability Service:
- This service is used by parking supervisor based on the size of vehicle needs to be parked.
- This service takes vehicle size as input and based on the input, it searches for availability based on isOccupied flag of each parking spot of relevant size.
- The output of the service will be Spot ID, floor number and spot type (in case of special requirements such as disabled parking, electric vehicle charging, etc.)
Spot Check-in Service:
- This service tags a spot ID to a vehicle ID and marks the isOccupied flag to true in order to lock the spot until checkout.
- Takes vehicle ID, spot ID as inputs
- This service notes the check-in time which will be considered for fee calculation
Spot Check-out Service:
- This service unlocks a spot by untagging a spot from the vehicle ID.
- isOccupied flag will be marked false, making it available for the next assignment.
- Check-out time will be noted for fee calculation.
- Automatically triggers fee calculation service.
Fee calculation Service:
- This service calculates the fee to be charged based on the parameters such as duration, vehicle size and spot type.
- Based on the tariffs on duration and vehicle size, the arithmetic of fee amount will be calculated and printed.
Define Core Objects
Based on the requirements and use cases, identify the main objects of the system...
parking spot is the main class with the following data members:
- spotId
- floor
- size
- isOccupied
- vehicleId
- type
Analyze Relationships
Determine how these objects will interact with each other to fulfill the use cases...
Establish Hierarchy
Design inheritance trees where applicable to promote code reuse and polymorphism. This step involves identifying common attributes and behaviors that can be abstracted into parent classes...
Design Patterns
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
Structural design pattern such as Builder can be used for maintainability.
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 ParkingSpot{
String spotId
Integer floor
String size
Boolean isOccupied
String vehicleId
String type
} // Example
public class CheckinCheckoutService {
FeeCalculator feeCalculator = new FeeCalculator();
public ParkingSpot spotCheckin(String vehicleId, String spotId){
//
}
spotCheckout(){
//
feeCalculator.calculateFee();
}
}
public class FeeCalculator{
calculateFee(){
//
}
}
Adhere 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...