The State Hex
Altering behavior dynamically based on inner alignment.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Shifting
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// KOTLIN PATTERN //
interface FamiliarState {
fun interact()
}
class CalmState : FamiliarState {
override fun interact() = println("Familiar purrs.")
}
class EnragedState : FamiliarState {
override fun interact() = println("Familiar spits fire!")
}
class Familiar {
var state: FamiliarState = CalmState()
fun poke() = state.interact()
}
The State Hex
An entity whose behavior violently shifts based on internal configurations is a ticking time bomb of if-else conditionals. The State Hex extracts these behaviors into discrete state objects. By swapping the state reference at runtime, a Familiar transitions seamlessly from calm to enraged without tangled logic.
Runic Tags:
#kotlin
#behavioral
#state