Requirements
The parking lot system will be used to manage parking lots with different vehicle sizes, multiple Levels, and various parking spot sizes.
- Types of vehicles: Motorcycles, cars and buses
- Parking spots: Different sizes - small, medium and large
- Levels: the parking has multiple floors
Features:
- Parking spot assignment:
- The system should assign a spot for a vehicle based on its size and the spot size.
- The system should unassign and remove a vehicle from a spot.
2. Keep track of available spots
- The system and the users should be able to check spot availability in real-time
- provide an interface for users to show free spots per floor.
3. support multiple floors
- the system should manage parking across multiple floors, and enable users to park in any different spot on any different floor
- support handicapped parking spots
4. Fee calculation
- The system should calculate parking fees based on the duration of each parking session.
- different rates may apply based on vehicle size/type.
5. Users.
- The system should support different kinds of users (admin/ user(vehicle owner)
- Admin can configure parking lot settings.
- ActiveUsers can reserve spots, check availability, and review parking history.
Define Core Objects
ParkingLot
ParkingFloor
ParkingSpot
Vehicle
- Motorcycle
- Car
- Bus
ParkingTicket
Analyze Relationships
- ParkingLot and ParkingFloor:
- the parking lot contains multiple parking floors, and it manages the overall parking facility and finding available spots.
2.ParkingFloor and ParkingSpot:
- each floor contains multiple parking spots and finds an available spot for a vehicle.
3.ParkingSpot and vehicle:
- parking spot assigns an available spot for a vehicle.
4.ParkingTicket and Vehicle:
- when a vehicle enters the lot it gets a ticket, and the fee will be calculated according to vehicle entry time and exit time.
5. User and the parking lot system
- users interact with the system based on their role.
Establish Hierarchy
- Vehicle: a base class containing general attributes like licensePlate and size.
subclasses: Motorcycle, Car, Bus will inherit from Vehicle
- User: a base class that will contain general attributes like user ID, user name, and role
subclasses: Admin, attendant, and Activeuser will inherit from the user and interact with the system based on their role.
Design Patterns
Factory pattern
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 enum import Enum
import datetime
class VehicleType(Enum):
MOTORCYCLE = 1
CAR = 2
BUS = 3
class UserType(Enum):
ADMIN = 1
ATTENDANT = 2
ACTIVEUSER = 3
class Vehicle:
def init(self, v_type: VehicleType, licence_plate):
self.v_type = v_type
self.licence_plate = licence_plate
def get_type(self):
return self.v_type
class ParkingSpot:
def init(self, spot_ID, spot_vehicle_type: VehicleType, floor):
self.spot_ID = spot_ID
self.spot_vehicle_type = spot_vehicle_type
self.floor = floor
self.is_available = True
self.vehicle = None
def can_fit_vehicle(self, vehicle) -> bool:
v_type = vehicle.get_type()
if self.is_available and self.spot_vehicle_type == v_type:
return True
else:
print("vehicle do not fit in")
return False
def park_vehicle(self, vehicle) -> bool:
if self.can_fit_vehicle(vehicle):
self.is_available = False
return True
else:
print("can't park vehicle"
return false
def remove_vehicle(self):
self.is_available = True
class ParkingFloor:
def init(self, floor_ID, spots):
self.floor_ID = floor_ID
self.spots = spots
def park_vehicle(self, vehicle) -> bool:
for spot in self.spots:
if spot.can_fit_vehicle(vehicle):
return spot.park_vehicle(vehicle)
return False
def remove_vehicle(self, vehicle) -> bool:
for spot in self.spots:
if spot.vehicle.license_plate == vehicle.license_plate:
spot.remove_vehicle()
return True
print("Vehicle is not in this floor:" + self.floor_ID)
return False
class ParkingLot:
def init(self, floors, spots, rate=20):
self.floors = floors
self.spots = spots
self.id_counter = 0
self.rate = rate
def park_vehicle(self, vehicle):
for floor in floors:
if floor.park_vehicle(vehicle):
entry_time = datetime.datetime.now()
ticket= ParkingTicket(self.id_counter, vehicle.licence_plate, entry_time)
self.id_counter+=1
def remove_vehicle(self, vehicle, ticket):
for floor in floors:
if floor.remove_vehicle(vehicle):
exit_time = datetime.datetime.now()
return self.calculate_fee(ticket, exit_time)
def calculate_fee(ticket:ParkingTicket, exit_time):
parking_duration = ticket.entry_time - self.exist_time
return self.rate * parking_duration
class ParkingTicket:
def init(self, ticket_ID, vehicle, entry_time):
self.ticket_ID = ticket_ID
self.vehicle = vehicle
self.entry_time = entry_time
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.)...
single responsibility
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...