Factory Method
Delegating the specific nature of a century-long enchantment to subclasses.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Transmutation // Genesis
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RAKU PATTERN //
role Enchantment {
method cast() { ... }
}
class HundredYearSleep does Enchantment {
method cast() { say "The subject falls into a slumber until a century has passed." }
}
class HundredYearVigil does Enchantment {
method cast() { say "A stone gargoyle awakens to guard the keep for 100 years." }
}
role SpellCrafter {
method create-enchantment(--> Enchantment) { ... }
method invoke() {
my $ench = self.create-enchantment();
say "Preparing the ceremonial circles...";
$ench.cast();
}
}
class SleepCrafter does SpellCrafter {
method create-enchantment(--> Enchantment) { HundredYearSleep.new }
}
class VigilCrafter does SpellCrafter {
method create-enchantment(--> Enchantment) { HundredYearVigil.new }
}
my SpellCrafter $crafter = SleepCrafter.new;
$crafter.invoke();
The core invocation ritual is always the same: drawing circles, burning incense, and chanting the old words. But the spell born of the ritual differs. The Factory Method allows our SpellCrafter to dictate the shared process while leaving the exact nature of the Hundred-Year Enchantment to specific crafter lineages.
Runic Tags:
#creational
#factory-method
#raku
#hundred-year-spell