One cancel button, three different answers
transcript
You order dinner, and then change your mind. You tap cancel. What happens depends on one thing: what already happened to the order.
Placed. The restaurant hasn't answered. Nothing is spent. You get all 300 back. Accepted. The kitchen has started cooking. You get half, 150. Picked up. The rider has it. Cancel is refused, with a clear message.
The order doesn't decide. It asks its current state, and waits. Each state answers in its own way. Refund, half, or refuse. The order never checks which state it holds. It just asks.
The alternative is an if on the status in every method. It works at first. A new state, like ready for pickup, edits every one of them. With State, a new state is a new place. The rest is untouched.
When behaviour depends on history, give each state a place. And let the object ask it.
Full breakdown in the lecture.