✨ ARCANUM RUNE DIFFICULTY: Adept Behavioral

The Memento

Capturing and restoring an object's internal state to rewind temporal errors.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Chronomancy // Temporal Reversion
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
class SoulCrystal {
  constructor(private state: string) {}
  getState() { return this.state; }
}

class MageEntity {
  private hp: number = 100;
  
  saveState(): SoulCrystal {
    return new SoulCrystal(JSON.stringify({ hp: this.hp }));
  }
  
  restoreState(memento: SoulCrystal) {
    const state = JSON.parse(memento.getState());
    this.hp = state.hp;
    console.log(`HP restored to ${this.hp}`);
  }
  
  takeDamage() { this.hp -= 20; }
}

The Memento pattern captures and externalizes an object’s internal state without violating encapsulation. It serves as a literal chronomantic save point, allowing a mage to store their current condition in a Soul Crystal and revert back when reality fragments into undesirable outcomes.

Runic Tags: #behavioral #typescript #memento