The Template Method
Locking down the macro-ritual while overriding the micro
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Template Method
ARCANUM SCHOOL: Evocation // Ritual Structure
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// HAXE PATTERN //
abstract class GrandRitual {
public function new() {}
// The Template Method
public final function performRitual():Void {
prepareComponents();
chant();
releaseEnergy();
}
private function prepareComponents():Void {
trace("Gathering base mana...");
}
// Hooks to be overridden
abstract private function chant():Void;
abstract private function releaseEnergy():Void;
}
class FireStormRitual extends GrandRitual {
private function chant():Void {
trace("Chanting the words of cinder and ash.");
}
private function releaseEnergy():Void {
trace("A massive fireball erupts!");
}
}
The Template Method seals the skeleton of an algorithm inside a final base function, preventing rogue apprentices from disrupting the critical sequence of operations. Specific hooks like the chant and releaseEnergy are left abstract for safe specialization in subclasses.
Runic Tags:
#evocation
#template-method
#haxe