Level 1 · Apprentice0 XP
When behaviour depends on a stage, give each stage its own type.
Step 1 / 5
ProblemAn order can be new, paid, shipped or cancelled. pay(), ship() and cancel() each start with a ladder of status checks. A fifth status arrives and nobody is sure which ladders to update. A shipped order gets cancelled in production.
← → step
Before this: Command: a request as an object
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Draw the state diagram of a support ticket: Open, InProgress, WaitingForCustomer, Resolved, Closed. Then model it as a sealed interface where each state has only its legal transitions. Try to write an illegal move and watch it not compile.