Replace order flags with an ADT
Model order lifecycle states with algebraic data types instead of coordinated flags.
An order model uses coordinated booleans: isPaid, isPacked, isShipped, isDelivered, isCancelled, plus optional payment and tracking fields. Algebraic Data Type: one lifecycle value, explicit cases, case-specific data. The novice move is to add isReturned as another flag. That multiplies combinations and guarantees another impossible dashboard state later. Step 1 List the real lifecycle states: Draft, Paid, Packed, Shipped, Delivered, Cancelled, RefundPending, Refunded. Start from business meaning, not existing fields. The model should reflect the real process. Step 2 Attach only case-specific data: Paid(paymentId), Shipped(trackingId), Cancelled(reason), Refunded(refundId). Each variant carries the data that is valid for that state and nothing else.…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in