The Strategy
Swapping combat algorithms mid-battle using enums
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Evocation // Tactical Casting
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// HAXE PATTERN //
// Haxe ADT magic for Strategy
enum CombatTactic {
Aggressive(power:Int);
Defensive(shield:Int);
Evasive;
}
class Tactician {
public var strategy:CombatTactic;
public function new(strategy:CombatTactic) {
this.strategy = strategy;
}
public function executeTurn():Void {
switch (strategy) {
case Aggressive(power):
trace('Attacking recklessly with $power damage!');
case Defensive(shield):
trace('Raising barriers blocking $shield damage!');
case Evasive:
trace('Dodging into the ethereal plane!');
}
}
}
While traditional OOP Strategy uses interfaces, Haxe’s robust enums (Algebraic Data Types) provide a much more functional, idiomatic approach. Swapping a tactic changes the pattern matching behavior instantly without the overhead of heavy class inheritance.
Runic Tags:
#evocation
#strategy
#haxe