The State Metamorphosis
Allow a familiar to completely alter its behavior when its internal elemental alignment shifts.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Shapeshifting
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCALA PATTERN //
sealed trait ElementalState {
def attack(): String
}
case object Solid extends ElementalState {
def attack(): String = "Smash with stone fist!"
}
case object Liquid extends ElementalState {
def attack(): String = "Drown in a torrent!"
}
class Shapeshifter(var state: ElementalState) {
def shift(newState: ElementalState): Unit = state = newState
def strike(): Unit = println(state.attack())
}
The State pattern removes massive if/else conditionals, delegating behavior directly to pure, isolated state objects. Shapeshifting made type-safe.
Runic Tags:
#scala
#behavioral
#shapeshifting
#state-machine