Based on the requirements and use cases, identify the main objects of the system...
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...
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.
from enum import Enum
from datetime import datetime
class VehicleType(Enum):
CAR = 1
MOTORCYCLE = 2
TRUCK = 3
class SpotType(Enum):
MOTORCYCLE_SPOT = 1
COMPACT_SPOT = 2
LARGE_SPOT = 3
class Vehicle:
def init(self, license_plate, vehicle_type):
self.license_plate = license_plate
self.vehicle_type = vehicle_type
class ParkingSpot:
def init(self, spot_id, spot_type):
self.spot_id = spot_id
self.spot_type = spot_type
self.is_occupied = False
self.parked_vehicle = None
def is_available(self):
return not self.is_occupied
def park_vehicle(self, vehicle):
self.parked_vehicle = vehicle
self.is_occupied = True
def remove_vehicle(self):
self.parked_vehicle = None
self.is_occupied = False
class ParkingFloor:
def init(self, floor_number, spots_per_type):
self.floor_number = floor_number
self.parking_spots = []
self.available_spots_count = {st: count for st, count in spots_per_type.items()}
# Initialize parking spots based on spots_per_type
def find_available_spot(self, vehicle_type):
# Logic to find a suitable spot based on vehicle_type
pass
class ParkingLot:
def init(self, name, num_floors, spots_per_floor):
self.name = name
self.levels = [ParkingFloor(i, spots_per_floor) for i in range(num_floors)]
self.tickets = {}
def park_vehicle(self, vehicle):
# Logic to find a spot, issue a ticket, and park the vehicle
pass
def exit_vehicle(self, ticket_id):
# Logic to remove vehicle, calculate fees, etc.
pass
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...