Bird
0
0

You need to design an order state machine that supports Pending, Processing, Shipped, Delivered, and Cancelled states. Which design choice best ensures scalability and maintainability?

hard📝 Trade-off Q8 of 15
LLD - Design — Online Shopping Cart

You need to design an order state machine that supports Pending, Processing, Shipped, Delivered, and Cancelled states. Which design choice best ensures scalability and maintainability?

AImplement a state transition table with allowed moves
BUse a hardcoded if-else chain for state transitions
CAllow any state to transition to any other state
DStore states as strings without validation
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate design options for scalability

    Hardcoded if-else is hard to maintain; allowing any transition is unsafe.
  2. Step 2: Choose best practice

    A transition table clearly defines allowed moves and is easy to update.
  3. Final Answer:

    Implement a state transition table with allowed moves -> Option A
  4. Quick Check:

    Scalable design = Transition table [OK]
Quick Trick: Use tables for clear, scalable transitions [OK]
Common Mistakes:
  • Hardcoding logic everywhere
  • Allowing invalid transitions
  • Ignoring validation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes