Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.
Primary functions:
Actors:
Based on the requirements and use cases, identify the main objects of the system...
Objects:
Determine how these objects will interact with each other to fulfill the use cases...
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 has a base class with size abstract method
Floor has a base class with vehicle type abstract method
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
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 ParkingLot:
def __init__(self):
self.floors = [] # List[Floor]
self.total_capacity = 0 # int
def add_floor(self, floor):
self.floors.append(floor)
self.total_capacity += floor.capacity
class Floor:
def init(self, floor_id, capacity):
self.floor_id = floor_id # int or str
self.spots = [] # List[ParkingSpot]
self.capacity = capacity # int
def add_spot(self, spot):
self.spots.append(spot)
def get_available_spots(self, vehicle_size):
# Return list of available spots that match vehicle size
pass
class ParkingSpot:
def init(self, spot_id, size):
self.spot_id = spot_id # str
self.size = size # str ("small", "medium", "large")
self.status = "available" # "available", "occupied", "reserved"
def occupy(self):
self.status = "occupied"
def free_up(self):
self.status = "available"
class Vehicle:
def init(self, vehicle_id, size):
self.vehicle_id = vehicle_id # str
self.size = size # str ("small", "medium", "large")
class Ticket:
def init(self, ticket_id, vehicle_id, spot_id, entry_time):
self.ticket_id = ticket_id
self.vehicle_id = vehicle_id
self.spot_id = spot_id
self.entry_time = entry_time # datetime
self.exit_time = None # datetime
def close_ticket(self, exit_time):
self.exit_time = exit_time
def get_duration(self):
return self.exit_time - self.entry_time
class FeeCalculator:
def calculate_fee(self, entry_time, exit_time):
duration = exit_time - entry_time
return (duration.total_seconds() / 3600) * 2 # $2/hour
class ParkingLotManager:
def init(self, parking_lot):
self.parking_lot = parking_lot # ParkingLot
self.tickets = {} # Dict[ticket_id: Ticket]
def check_availability(self, vehicle):
# Iterate through floors and spots to find a match
pass
def create_ticket(self, vehicle, spot, entry_time):
ticket_id = generate_unique_id()
ticket = Ticket(ticket_id, vehicle.vehicle_id, spot.spot_id, entry_time)
spot.occupy()
self.tickets[ticket_id] = ticket
return ticket
def close_ticket(self, ticket_id, exit_time):
ticket = self.tickets.get(ticket_id)
ticket.close_ticket(exit_time)
fee = FeeCalculator().calculate_fee(ticket.entry_time, exit_time)
# Free up the spot
# return fee and ticket summary
return fee
Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...
Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...
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...
Critically examine your design for any flaws or areas for future improvement...