Design: Elevator Control System
Design the core classes and their interactions for elevator, floor, and request management. Exclude hardware control and detailed UI design.
Functional Requirements
Non-Functional Requirements
Jump into concepts and practice - no test required
+----------------+ +----------------+ +----------------+
| Floor |<----->| Controller |<----->| Elevator |
+----------------+ +----------------+ +----------------+
^ ^ ^ ^
| | | |
Floor requests Assign requests Elevator state
(up/down buttons) (pickup/dropoff) (current floor,
direction, requests)Request class in an elevator system?Request class constructor in Python to store floor and direction?def __init__(self, ...) and assign attributes with self.attribute = value.self and assigns floor and direction. Others miss self or parameters.class Request:
def __init__(self, floor, direction):
self.floor = floor
self.direction = direction
r = Request(5, 'up')
print(r.floor, r.direction)r.floor and r.direction outputs 5 and 'up' respectively.class Elevator:
def __init__(self, current_floor):
self.current_floor = current_floor
def move_to(self, floor):
current_floor = floor
current_floor = floor without self., so it changes a local variable only.self.current_floor = floor.Elevator, Floor, and Request classes, which approach best handles multiple simultaneous requests efficiently?