The Template Method Hex
Define the skeleton of an algorithm, deferring some steps to subclasses.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Template Method
ARCANUM SCHOOL: Evocation // Ritual Skeletons
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
use fmt;
type Ritual = struct {
prepare: *fn() void,
cast: *fn() void,
cleanup: *fn() void,
execute: *fn(r: *Ritual) void,
};
fn base_execute(r: *Ritual) void = {
r.prepare();
r.cast();
r.cleanup();
};
fn pyromancy_prepare() void = { fmt::println("Gathering heat...")!; };
fn pyromancy_cast() void = { fmt::println("Unleashing Fireball!")!; };
fn pyromancy_cleanup() void = { fmt::println("Extinguishing embers.")!; };
export fn main() void = {
let fireball = Ritual {
prepare = &pyromancy_prepare,
cast = &pyromancy_cast,
cleanup = &pyromancy_cleanup,
execute = &base_execute,
};
fireball.execute(&fireball);
};
A ritual must be followed precisely—prepare, cast, cleanup. The Template Method hex enforces the sequence while allowing the specific magical focus (fire, ice, void) to be slotted in as needed.
Runic Tags:
#behavioral
#template-method
#simple-systems-hexes