MΓ³dulo 23 Β· Design Patterns (All 23 GoF) β LecciΓ³n 20 de 23 Β· ~6 min
State
State: behavior changes with internal state
Problem: an object behaves differently depending on which state it's in, and only certain transitions are legal.
PawWalk scenario: a booking machine β requested -> confirmed -> in_progress -> completed, with cancelled reachable from a few states. Illegal jumps must be rejected.
A clean Ruby realization: a map of allowed transitions and a transition method that consults it, raising on an illegal move.