Requirements
- Assign parking spot based on vehicle size.
- Parking spot availability check.
- Calculate fees based on the parking duration.
Define Core Objects
- class ParkingInfo -> -availableSpotsSedan, -availableSpotsSuv, -availableSpotsTruck, -parkingLocation, -duration -availability_map
- class Vehicle -> size (Sedan, Suv, Truck) , vehicleId
- class Fees -> +calculateFees
Analyze Relationships
Determine how these objects will interact with each other to fulfill the use cases...
ParkingInfo will need a Vehicle object to get size for parking assiginment
Fees will need a Vehicle Object and ParkingInfo object to get vehicleId and calculate duration for each vehicle
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...
Vehicle could a parent class of Car, Motocycle etc
Design Patterns
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
Could use Strategy for Fees class to calcualte the fees based on vehicle size
if size == "Sedan": fees = SEDAN_PRICE * duration
elif size == "Truck": fees = SEDAN_PRICE * duration
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.
class ParkingInfo:
def __init__(self, car):
self.available_spots_sedan = 100
self.available_spots_suv = 100
self.available_spots_trucks = 100
self.parking_location = {} # vihecle_id: B25 etc.
self.availability_set = set() # check if the spot it's taken
duration_map = {} #vihecle_id: (timestamp_start, timestamp_end)
self.car = car
def assign_parking_spot():
vihecle_id = self.car.get_vihecle_id
if self.car.get_size() == "Sedan":
spot_num = 100
if
while 'A' + str(spot_num) in self.availability_map:
spot_num -= 1
spot_id = 'A' + str(spot_num)
self.available_spots_sedan -=1
self.availability_set.add('A' + str(spot_num)
self.parking_location[vihecle_id] = spot_id
def get_duration(vihecle_id):
start, end = self.duration_map[vihecle_id][0], self.duration_map[vihecle_id][1]
return end - start
class Car:
def init(self, size, vihecle_id):
self.size = size
self.vihecle_id = vihecle_id
def get_vihecle_id():
return self.vihecle_id
def get_size():
return self.size
class Fees:
def init(self, parking_info, car):
self.rate = 5 # 5 dollars per hour
self.duration = parkingInfo.get
self.parking_info = parking_info
def calculate_fees():
duration = self.parking_info.get_duration()
if duration < 1: # less than one hour
return self.rate
return self.rate * duration
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.)...
Its cohesive to single responsibility, each class serves its own purpose.
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
Could be improved by refactoring