Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.
I'll start out my listing some fundamental requirements and add specialised requirements later.
Functional:
Non-functional:
Based on the requirements and use cases, identify the main objects of the system...
Three types of entities
Objects:
Services:
Interfaces:
Determine how these objects will interact with each other to fulfill the use cases...
User interacts with the system through interfaces (Inside and Outside). Each interface will have a generate request method which will send a request object to the elevatorController. The elevator controller will scan the list of elevators and assign some eleavtor based on some logic. This will add the request to the elevator's queue. The elevator assign logic will include considering the status of the elevator (moving, direction) and current floor number.
In the end the interface will recieved an elevator number. Once the elevator services a requerst, it will call doop_open function and door close functions.
The user can then use the inside interface to send the next request.
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
class Elevator:
def init(self, id, floors, isMoving = False, direction = Direction.STILL, currFloor = 0):
self.id = id
self.floors = floors
self.__isMoving = isMoving
self.__direction = direction
self.queue = Queue()
self.currFloor = currFloor
def isInMotion(self):
return self.__isMoving
def getDirection(self):
return self.isInMotion() and self.__direction
def isSameDirection(self, Direction):
return self.getDirection() == direction
def addRequest(self, Request):
self.queue.add(Request)
def move(self):
prev_floor = self.currFloor
self.currFloor= self.queue.pop()
if self.queue.isEmpty():
self.__isMoving = False
else:
self.__isMoving = True
class User(ABC):
def init(self, id):
self.id = id
class Passenger(User):
class Admin(User):
class Button(ABC):
def init(self):
self.__isPressed = False
class UpButton(Button):
def init(self):
super().init()
class DownButton(Button):
def init(self):
super().init()
class NumButton(Button):
def init(self, number):
super().init()
self.number = number
class Direction(Enum):
STILL = 0
UP = 1
DOWN = 2
class Request(ABC):
def init(self, requested_floor_id):
self.requested_floor_id = requested_floor_id
class InsideRequest(Request):
def init(self):
super().__init()
class OutsideRequest(Request):
def init(self, direction):
super().__init()
self.direction = direction
class AdminRequest(Request):
def init(self, direction, emergency = False):
super().__init()
self.direction = direction
self.emergency = emergency
class Queue:
def init(self, queue = None):
self.queue = queue if queue is not None else []
class ElevatorController:
def init(self, elevators, floors):
self.elevators = elevators
self.floors = floors
def
class ElevatorManager:
class Interface(ABC):
class InsideInterface(Interface):
class OutsideInterface(Interface):
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...