The Tactician Strategy
Define a family of magical algorithms, encapsulate each one, and make them interchangeable.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Evocation // Tactics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JAVASCRIPT IDIOMATIC PATTERN //
class AttackStrategy { execute() {} }
class FireballStrategy extends AttackStrategy {
execute() { console.log("Casting devastating AoE Fireball!"); }
}
class MagicMissileStrategy extends AttackStrategy {
execute() { console.log("Firing precise Magic Missiles."); }
}
class BattleMage {
setStrategy(strategy) { this.strategy = strategy; }
attack() { this.strategy.execute(); }
}
const mage = new BattleMage();
mage.setStrategy(new FireballStrategy());
mage.attack();
mage.setStrategy(new MagicMissileStrategy());
mage.attack();
The Tactician Strategy
A Battle Mage does not rely on a single spell. Depending on the foe, they swap their methodology entirely. The Strategy pattern lets the algorithm vary independently from the clients that use it.
Runic Tags:
#algorithms
#tactics
#swapping