The Singleton
Guaranteeing a singular, universal locus of control across the arcane network.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Leyline Control
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
class LeylineNexus {
private static instance: LeylineNexus;
public manaReserves: number;
private constructor() {
this.manaReserves = 10000;
}
public static getInstance(): LeylineNexus {
if (!LeylineNexus.instance) {
LeylineNexus.instance = new LeylineNexus();
}
return LeylineNexus.instance;
}
public tapMana(amount: number): void {
this.manaReserves -= amount;
}
}
The Singleton pattern ensures a class only has one instance, providing a global point of access to it. Perfect for managing a singular resource like the central Leyline Nexus or an application’s root registry of spell effects, ensuring multiple mages don’t disrupt the shared state.
Runic Tags:
#creational
#typescript
#singleton