Requirements


  1. System should be able to park a car on a specific

floor.

  1. Spots are assigned to vehicles based on the size, spot availability.
  2. Fee for user is calculated based on parking duration.





Define Core Objects


  1. Parking Lot
  2. Vehicle
  3. Spot
  4. Floor
  5. Payment
  6. User
  7. Ticket



Analyze Relationships


  1. Floor has spots
  2. ParkingLot has floors
  3. Parking has a payment
  4. Car,Truck,Bike is a Vehicle
  5. Parking sport either has a vehicle or is vacant
  6. When a vehicle is parked ticket is generated recording the entry time.
  7. Users interact with the system based on their role.






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...


  1. We will create a parkingLot which will have attributes like Spot,floors etc.
  2. There will be Vehicle base class and classes like Car,Truck,Bike etc will inherit from base Vehicle class.
  3. There will be User class will special privilege. (Can be customer,Admin etc)
  4. There will be Ticket class
  5. There will be payment class which will generate receipt based on vehicle enrty,exit time listed on User Ticket.



Design Patterns

Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...






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 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)









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...