The Singleton Incantation
Ensuring only one instance of an ancient artifact exists within the kernel's memory space.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Singularity
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// MATHEMATICA PATTERN //
(* Establishing a protected namespace for the Singleton *)
Begin["`Private`"];
ClearAll[GetPhilosophersStone];
(* The uninitialized state *)
$stoneInstance = Null;
(* The Accessor Ritual *)
GetPhilosophersStone[] :=
If[$stoneInstance === Null,
Print["Forging the Philosopher's Stone..."];
$stoneInstance = {"Name" -> "Philosopher's Stone", "Power" -> Infinity};
$stoneInstance,
Print["The Stone already exists. Retrieving resonance..."];
$stoneInstance
];
End[];
(* Usage *)
stone1 = GetPhilosophersStone[];
stone2 = GetPhilosophersStone[];
Print["Are they the same? ", stone1 === stone2];
Runic Tags:
#singleton
#state
#encapsulation
#singularity