Requirements
Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.
Functional:
- Assign parking spot to new vehicle (system should)
- Calculate fare based on duration at checkout (system)
- Monitoring parking spots (admin)
- User's iterface will include operations like get parking spot and checkout
Non-functional:
- If multiple entrances, there should be consistency is assignment. No duplicate assignments
- Low spot assignment latency
Define Core Objects
Based on the requirements and use cases, identify the main objects of the system...
- Parking Lot
- Floor
- Parking Spot
- Spot size -> Enum
- Vehicle
- Car
- Motorcycle
- Truck
- Ticket
Services:
- ParkingSpotAssignment (internal)
- MonitorSpots(internal or used by admin)
- FareCalculator (used by user)
- ReservationService (used by user)
Analyze Relationships
Determine how these objects will interact with each other to fulfill the use cases...
Based on the core entities this is how the objects will interact.
User with car calls the reservation service which calls the parking spot assigment service. This gets the available spots from MonitorSpots service and returns details to the reservation service which generates a ticke object and assigns the vehcile ID to it.
the ticket object will have in time, out time, vehicle id, parking spot id.
On checkout the user will call the fare calculator to calculate the the fare based on fixed formula and in and out time on ticket
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...
I dont know
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.
from abc import ABC, abstractmethod
from enum import Enum
class SpotSize(Enum):
SMALL = 'small'
MEDIUM = 'medium'
LARGE = 'large'
class Vehicle(ABC):
def init(self, lisence_plate, min_size ):
self.lisence_plate = lisence_plate
self.min_size = min_size
class Car(Vehicle):
def init(self, lisence_plate, min_size, ...):
super().init(lisence_plate, min_size)
class MotorCycle(Vehicle):
def init(self, lisence_plate, min_size, ...):
super().init(lisence_plate, min_size)
class Truck(Vehicle):
def init(self, lisence_plate, min_size, ...):
super().init(lisence_plate, min_size)
class ParkingLot:
def init(self, floors):
self.floors = floors
class Floor:
def init(self, parkingspots):
self.parkingspots= parkingspots
class ParkingSpot:
def init(self, size, occupied):
self.size= size
self.occupied = occupied
class Ticket:
def init(self, vehicle_id, spot_id, floor_id, in_time, out_time = None):
self.vehicle_id = vehicle_id
self.spot_id= spot_id
self.floor_id= floor_id
self.in_time= in_time
self.out_time = out_time
Moving on to the services
class MonitorParkingSpots:
def init(self, ParkingLot):
self.ParkingLot = ParkingLot
def get_available_spots(self, spot_size):
available_spots = []
for floor in self.ParkingLot.floors:
for spot in floor.parkingspots:
if not spot.occupied and spot_size >= spot.size:
available_spots.append((floor.floor_id, spot.spot_id)
return available_spots
class ParkingSpotAssign:
def init(self, ParkingLot):
self.monitoring_serivice = MonitorParkingSpots(ParkingLot)
def assign_spot(self, vehicle):
available_spots = self.monitoring_serivice.get_available_spots(vehicle.size)
# logic to get optimum spot from list of spots
return floor_id, spot_id
class ReservationService:
def init(self, ParkingLot):
self.ParkingLot = ParkingLot
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...