The State Morph
Altering an object's behavior when its internal state changes.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Polymorphism
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module StatePattern where
open import Data.String
record State : Set where
field handle : String → String
record Context : Set where
field currentState : State
The State Morph
A weapon might act as a sword or an energy whip depending on its internal heat capacity. The State Morph pattern treats each mode as a distinct entity, seamlessly swapping its operational core at runtime.
The Dependent Runes
In functional lands, this is a Finite State Machine. A Context carries the current State behavior dictionary. State transitions are just functions returning a modified Context.
Runic Tags:
#agda
#state
#fsm