⚙️ LEAN RUNE DIFFICULTY: Apprentice Behavioral

The Template Method

Defining the unalterable ritual skeleton of an absolute ward, while deferring the exact runes to the invocation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Template Method
ARCANUM SCHOOL: Evocation // Rituals
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// LEAN PATTERN //
namespace MathematicalWards

structure RitualHooks where
  drawCircle : Unit → String
  chantAxiom : Unit → String
  sealWard : Unit → String

def performRitual (hooks : RitualHooks) : String :=
  let s1 := hooks.drawCircle ()
  let s2 := hooks.chantAxiom ()
  let s3 := hooks.sealWard ()
  s1 ++ " -> " ++ s2 ++ " -> " ++ s3

def fireRitual : RitualHooks :=
  { drawCircle := fun _ => "Draw ring of fire",
    chantAxiom := fun _ => "Axiom of Combustion",
    sealWard := fun _ => "Seal with ash" }

#eval performRitual fireRitual

end MathematicalWards

Instead of overriding subclass methods, the Template Method here is realized by accepting a structure of function hooks that fill in the variable steps of the algorithm.

Runic Tags: #behavioral #lean4 #template-method #wards