Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.
Who are the users:
What are the core features:
What are the constraints:
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...
Common attributes:
Common behaviors:
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
Factory pattern:
Observer pattern:
Strategy pattern:
Singleton pattern:
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 datetime import datetime
class User:
def init(self, id):
self.userId = id
class Vehicle(ABC):
def init(self, license):
self.license = license
@property
@abstractmethod
def hourlyRate(self):
pass
class Car(Vehicle):
hourlyRate = 10
def __init__(self, license, make, model, size):
super().__init__(license)
self.make = make
self.model = model
self.size = size
class Motorcycle(Vehicle):
hourlyRate = 5
def __init__(self, license):
super().__init__(license)
self.size = "moto"
class Garage:
def init(self, id, floors):
self.id = id
self.floors = [GarageFloor(f) for f in range(floors)]
def getSummary(self):
spaces = {}
for f in self.floors:
for s in f.spaces:
spaces[s.size] = spaces.get(s.size, 0) + 1
return spaces
class GarageFloor:
def init(self, level, spaces):
self.level = level
self.spaces = []
# Create n spaces of each type
for t, n in spaces:
for i in range(1, n + 1):
spaces.append(ParkingSpace(i, t))
def getAvailableSpace(self, size):
for s in self.spaces:
if s.size == size:
return s
class ParkingSpace:
def init(self, number, size):
self.number = number
self.size = size
self.isOccupied = False
def parkCar(self):
self.isOccupied = True
def releaseSpace(self):
self.vehicle = None
self.isOccupied = False
class Ticket:
def init(self, v: Vehicle, space: ParkingSpace):
self.startTime = datetime.now()
self.vehicle = v
self.space = space
space.parkCar() # Space assigned when a ticket is made
def calculateFee(self) -> float:
self.endTime = datetime.now()
return (self.endTime - self.startTime) * self.v.hourlyRate
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...