Bird
0
0

Examine the following method in an order state machine:

medium📝 Analysis Q6 of 15
LLD - Design — Online Shopping Cart

Examine the following method in an order state machine:

def refund_order(self):
    if self.state == 'Delivered':
        self.state = 'Refunded'
    else:
        print('Refund not allowed')

What is the issue with this implementation?

AIt incorrectly changes state without validation
BIt allows refund only after delivery, ignoring cancellations
CIt permits refund from any state
DIt does not handle the 'Refunded' state properly
Step-by-Step Solution
Solution:
  1. Step 1: Review the refund logic

    The method allows refund only if the order is in 'Delivered' state.
  2. Step 2: Identify missing cases

    Refunds might also be valid for 'Cancelled' orders or other states depending on business rules, but this method ignores them.
  3. Final Answer:

    It allows refund only after delivery, ignoring cancellations -> Option B
  4. Quick Check:

    Check if all valid refund states are covered [OK]
Quick Trick: Check if all valid states are handled for refund [OK]
Common Mistakes:
  • Assuming refund only after delivery is valid
  • Not validating current state before transition
  • Ignoring business rules for refunds

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes