The Template Method
Define the skeleton of an algorithm in an operation, deferring some steps to subclasses.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Template Method
ARCANUM SCHOOL: Abjuration // Ritual Frameworks
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
structural type RitualSteps = {
prepare : () -> Text,
execute : () -> Text,
cleanup : () -> Text
}
performRitual : RitualSteps -> Text
performRitual steps =
p = RitualSteps.prepare steps ()
e = RitualSteps.execute steps ()
c = RitualSteps.cleanup steps ()
p ++ " | " ++ e ++ " | " ++ c
summonDemon : RitualSteps
summonDemon = RitualSteps
(_ -> "Draw pentagram")
(_ -> "Speak true name")
(_ -> "Banish sulfur")
When the structure of a high-level ritual must remain rigid but the internal incantations must vary, the Template Method is employed. In Unison, we use a record containing the specific step functions. The master function, performRitual, dictates the exact ordering and orchestration of the execution, while the specific RitualSteps record passed in defines the localized arcane mechanics.
Runic Tags:
#behavioral
#template-method
#unison
#records