Loading...
For each class, define the attributes (data) it will hold and the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.
class ElevatorStatus(Enum):
AVAILABLE = 1
UNVAILABLE = 2
class ElevatorDirection(Enum):
IDLE = 0
UP = 1
DOWN = 2
class Elevator:
def init(self, status, floor):
self.status = status
self.currentFloor = floor
self.direction = ElevatorDirection.IDLE
def move(self, targetFloor):
self.currentFloor = targetFloor
if self.currentFloor > targetFloot:
self.direction = ElevatorDirection.UP
else:
self.direction = ElevatorDirection.DOWN
def stop(self):
self.direction = ElevatorDirection.IDLE
def isAvailable(self):
return self.status.value == 1
def isIdle(self):
return self.direction.value == 0
def isGoingUp(self):
return self.direction.value == 1
def isGoingDown(self):
return self.direction.value == 2
class ElevatorRequests:
_instance = None
def new(cls):
if cls._instance is None:
cls._instance = object.new(cls)
cls.fifo = deque([])
return cls._instance
def isEmpty(self):
return len(self.fifo) == 0
def addRequest(self, requestingFloor):
self.fifo.append(requestingFloor)
def getRequest(self, requestingFloor):
self.fifo.popleft()
class callElevatorStrategy:
def callElevator(self, elevators, targetFloot):
pass
class callClosestElevatorStrategy:
def callElevator(self, elevators, targetFloot):
# algorithm to get closest elevator
class callElevatorPassingStrategy:
def callElevator(self, elevators, targetFloot):
# algorithm to get elevator that will pass current floor
class ElevatorController:
def init(self, elevators):
self.elevators = elevators
def assignElevator(self, strategyID, currentFloot):
callStrategy = None
match strategyID:
case 1:
callStrategy = callElevatorPassingStrategy()
case 2:
callStrategy = callClosestElevatorStrategy()
return callStrategy.callElevator(self.elevators, currentFloor)
class ElevatorSystem:
def init(self, numElevators):
self.numElevators = numElevators
self.elevators = [Elevator(ElevatorStatus.Available,0) for i in range(numElevators)]
self.elevatorRequests = ElevatorRequests()
self.elevatorController = ElevatorController(self.elevatorRequests, self.elevators)
def dispatch(self, strategy=1):
while True:
if not self.elevatorRequests.isEmpty():
floorNumber = self.elevatorRequests.getRequest()
assignedElevator = self.elevatorController.assignElevator(strategy, self.elevators)
assignedElevator.move(floorNumber)
Explain design tradeoffs you considered. Check and explain whether your design adheres to SOLID principles. Explain how your design can handle changes in scale and whether it would be easy to extend with new functionalities. Identify areas for future improvement...