✨ ARCANUM RUNE DIFFICULTY: Apprentice Behavioral

The Strategy

Encapsulating interchangeable families of algorithms to dynamically select combat tactics.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Divination // Tactical Analysis
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
interface CombatStrategy {
  execute(target: string): void;
}

class StealthStrike implements CombatStrategy {
  execute(target: string) { console.log(`Infiltrating and striking ${target} silently.`); }
}

class FrontalAssault implements CombatStrategy {
  execute(target: string) { console.log(`Unleashing devastating force on ${target}.`); }
}

class CyberMage {
  constructor(private strategy: CombatStrategy) {}
  
  setStrategy(strategy: CombatStrategy) { this.strategy = strategy; }
  
  engage(target: string) { this.strategy.execute(target); }
}

The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. It lets the algorithm vary independently from clients that use it. A Cyber Mage can swap seamlessly between Stealth and Assault strategies simply by hot-swapping strict-typed logic chips at runtime.

Runic Tags: #behavioral #typescript #strategy