The Template Method Hex
Defining the skeletal framework of an arcane ritual.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Template Method
ARCANUM SCHOOL: Divination // Pure Environment Hexes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
let
# The Template Method
mkStandardDerivation = hooks: {
name = hooks.name or "unknown-spell";
# The fixed algorithm skeleton
execute = ''
''${hooks.preBuild or "echo 'Preparing the circle...'"}
''${hooks.buildPhase or "echo 'Chanting default incantation...'"}
''${hooks.postBuild or "echo 'Sealing the circle.'"}
'';
};
# Concrete Implementations overriding hooks
fireballSpell = mkStandardDerivation {
name = "Fireball";
buildPhase = "echo 'Ignis!'";
};
in
fireballSpell.execute
The Template Method defines the skeleton of an algorithm, deferring some steps to subclasses or overrides. Nix’s stdenv.mkDerivation is a prime example: it provides a rigid phased structure (preBuild, buildPhase, etc.) that builders can optionally override.
Runic Tags:
#behavioral
#template-method
#nix
#frameworks