Bird
Raised Fist0

In a system managing states idle, moving_up, and moving_down, how can you combine state management with event logging to track all state changes efficiently?

hard📝 Trade-off Q9 of Q15
LLD - Design — Elevator System
In a system managing states idle, moving_up, and moving_down, how can you combine state management with event logging to track all state changes efficiently?
ALog only errors and ignore normal state changes
BImplement a state change handler that logs every transition before updating state
CLog state changes after updating state without handler
DUse separate logging system unrelated to state changes
Step-by-Step Solution
Solution:
  1. Step 1: Understand importance of logging state changes

    Logging every transition helps debugging and monitoring system behavior.
  2. Step 2: Best practice for logging

    Using a handler that logs before state update ensures accurate capture of old and new states.
  3. Final Answer:

    Implement a state change handler that logs every transition before updating state -> Option B
  4. Quick Check:

    Log transitions via handler before state update [OK]
Quick Trick: Log state changes before updating state for accuracy [OK]
Common Mistakes:
MISTAKES
  • Logging only errors
  • Logging after state update losing old state
  • Ignoring logging integration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes