The Factory Method
Delegating the instantiation of spells to localized subnetworks of magical subclasses.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Invocation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
interface Spell {
cast(): string;
}
class Fireball implements Spell {
cast() { return "A blazing sphere of network traffic erupts!"; }
}
abstract class Spellweaver {
abstract createSpell(): Spell;
invoke(): string {
const spell = this.createSpell();
return spell.cast();
}
}
class PyromancerWeaver extends Spellweaver {
createSpell(): Spell {
return new Fireball();
}
}
The Factory Method defines an interface for summoning an object, but leaves the choice of its type to the subclasses. This is the bedrock of polymorphic incantations, allowing a generic casting sequence to manifest dynamic, context-specific spell logic through strict type constraints.
Runic Tags:
#creational
#typescript
#factory