CHAPTER 1 OF 3
One order. Has it been paid?
A tiny checkout only records payment. A boolean prevents a second payment. For this requirement, a small check is clear and sufficient.
Appearance
STATE / THE WALKTHROUGH
Start with one payment check. Add lifecycle rules, then see what changes when each stage owns its behavior.
CHAPTER 1 OF 3
A tiny checkout only records payment. A boolean prevents a second payment. For this requirement, a small check is clear and sufficient.
This first version only records whether payment happened. It has no shipping or cancellation rules yet.
No payment recorded yet.
export class CheckoutOrder {
private paid = false;
pay(): boolean {
if (this.paid) return false;
this.paid = true;
return true;
}
}Chapter changes start a fresh example. Theme and language preserve the current step.