State Machines — Simple#
stateDiagram-v2
[*] --> Created
Created --> Paid : pay()
Created --> Cancelled : cancel()
Paid --> Shipped : ship()
Paid --> Refunded : refund()
Shipped --> Delivered : deliver()
Shipped --> Returned : return()
Delivered --> [*]
Refunded --> [*]
Cancelled --> [*]
Returned --> [*]
A finite state machine = (states, transitions, events, guards). Anything with a lifecycle — order, booking, ATM card, elevator cabin, video player — is a state machine. Model it explicitly; don't bury transitions in if-chains.