Bird
0
0

Which design choice best ensures scalability and clear control flow when adding more states like door open or maintenance?

hard📝 Trade-off Q15 of 15
LLD - Design — Elevator System
You are designing a state machine for an elevator with states 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?
AHardcode state changes inside each function without a state map
BUse a centralized state manager with explicit allowed transitions and event handlers
CUse global variables and if-else checks scattered across code
DIgnore state management and rely on random delays
Step-by-Step Solution
Solution:
  1. Step 1: Consider scalability and clarity

    A centralized state manager clearly defines states and allowed transitions, making it easier to add new states and maintain control flow.
  2. Step 2: Evaluate other options

    Using global variables or hardcoding state changes leads to messy, error-prone code. Ignoring state management causes unpredictable behavior.
  3. Final Answer:

    Use a centralized state manager with explicit allowed transitions and event handlers -> Option B
  4. Quick Check:

    Centralized state management = scalable and clear [OK]
Quick Trick: Centralize state logic for easier scaling and maintenance [OK]
Common Mistakes:
MISTAKES
  • Scattering state logic causing bugs
  • Hardcoding states making changes hard
  • Ignoring state management leads to chaos

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes