Design: Elevator State Management System
Design focuses on the state management logic and transitions for a single elevator. Hardware control and multi-elevator coordination are out of scope.
Functional Requirements
Non-Functional Requirements
Jump into concepts and practice - no test required
+---------------------+
| Elevator Controller |
+----------+----------+
|
v
+---------------------+
| State Machine |
| (Idle, Moving Up, |
| Moving Down) |
+----------+----------+
|
v
+---------------------+
| State Storage |
+---------------------+
|
v
+---------------------+
| Event Logger |
+---------------------+idle, moving up, and moving down?idle, moving up, and moving down?start at idle, move up, move down, idle?
state = 'idle'
if event == 'move up' and state == 'idle':
state = 'moving up'
elif event == 'move down' and state == 'idle':
state = 'moving down'
elif event == 'stop' and state in ['moving up', 'moving down']:
state = 'idle'idle, moving up, and moving down:
if state == 'idle' and event == 'move up':
state = 'moving up'
elif state == 'moving up' and event == 'move down':
state = 'moving down'
elif state == 'moving down' and event == 'stop':
state = 'idle'idle, moving up, and moving down. Which design choice best ensures scalability and clear control flow when adding more states like door open or maintenance?