floor.
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 abc import ABC,abstractmethod
from enum import Enum
import threading
class VehcileType(Enum):
Car=1
Bike=2
Truck=3
class ParkingSpot:
def init(self,spotId,isOccupied):
self.spotId=spotId
self.isOccupied=isOccupied
class Vehicle:
def init(self,vehicleType,number,color,name):
self.vehicleType=vehicleType
self.number=number
self.color=color
self.name=name
class ParkingFloor:
level=-1
spots=[]
totalSpots=0
availableSpots=0
def __init__(self,level,totalSpots,availableSpots):
self.level=level
self.totalSpots=totalSpots
self.availableSpots=availableSpots
def add_spot(self,spot):
self.spots.append(spot)
def findAvailableSpots(self):
for spot in self.spots:
if spot.isOccupied==False:
return spot
class ParkingLot:
_instance=None
_lock=threading.Lock()
parkingFloor=[]
totalSpots=0
availableSpots=0
@classmethod
def get_instance(cls):
if not cls._instance:
with cls._lock:
if not cls._instance:
cls._instance=super().__new__(cls)
return cls._instance
def assignSpot(self,Vehicle,Floor): # assign spot to a vehicle on this floor
spot=Floor.findAvailableSpots()
if spot and spot.isOccupied==False:
spot.isOccupied=True
spot.Vehicle=Vehicle
print(f"Spot {spot.spotId} assigned with Vehicle {Vehicle.number}")
def releaseSpot(self,spot):
spot.isOccupied=False
p1=ParkingLot.get_instance()
v1=Vehicle(VehcileType.Car,1234,"RED","lola")
f1=ParkingFloor(1,10,10)
ps1=ParkingSpot(1,False)
f1.add_spot(ps1)
p1.assignSpot(v1,f1)
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...