✨ ARCANUM RUNE DIFFICULTY: Adept Behavioral

The State

Allowing an entity to radically alter its behavior when its internal magical state shifts.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Metamorphosis
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
interface ElementalState {
  attack(): string;
}

class FireForm implements ElementalState {
  attack() { return "Unleashing a torrent of flame!"; }
}

class IceForm implements ElementalState {
  attack() { return "Shattering foes with glacial spikes!"; }
}

class ElementalShapeshifter {
  private state: ElementalState;
  constructor(state: ElementalState) { this.state = state; }
  
  changeForm(newState: ElementalState) { this.state = newState; }
  
  strike() { console.log(this.state.attack()); }
}

The State pattern allows an object to alter its behavior when its internal state changes. It appears as though the object changed its class. Perfect for entities like shapeshifters or adaptable combat drones that swap elemental affinities on the fly without unwieldy conditional statements.

Runic Tags: #behavioral #typescript #state