The Command
Encapsulating incantations for delayed execution
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Enchantment // Delayed Triggers
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// HAXE PATTERN //
interface IIncantation {
public function execute():Void;
public function undo():Void;
}
class Leyline {
public var active:Bool = false;
public function new() {}
public function activate():Void { active = true; trace("Leyline glowing."); }
public function deactivate():Void { active = false; trace("Leyline dark."); }
}
class ToggleLeylineCommand implements IIncantation {
private var leyline:Leyline;
public function new(leyline:Leyline) { this.leyline = leyline; }
public function execute():Void { this.leyline.activate(); }
public function undo():Void { this.leyline.deactivate(); }
}
class RitualMaster {
private var history:Array<IIncantation> = [];
public function new() {}
public function cast(incantation:IIncantation):Void {
incantation.execute();
history.push(incantation);
}
public function rollback():Void {
var last = history.pop();
if (last != null) last.undo();
}
}
The Command turns a spell into a tangible object, decoupling the entity that invokes the spell from the one that executes it. This delayed binding is crucial for queued rituals, rollback scenarios (undoing catastrophic backfires), and scheduling macro-spells.
Runic Tags:
#enchantment
#command
#haxe