The Singleton: The Singular Nexus
Ensure a class only has one instance, and provide a global point of access to it.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Binding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
public class GNOMEArtifice.NexusCore : Object {
private static NexusCore? instance = null;
public string energy_signature { get; private set; }
private NexusCore() {
this.energy_signature = "Void-Plasma";
}
public static NexusCore get_instance() {
if (instance == null) {
instance = new NexusCore();
}
return instance;
}
public void pulse() {
print(@"Nexus Core pulsing with $(this.energy_signature) energy.\n");
}
}
There are powers within the system that cannot, must not, be duplicated. The Nexus Core of the GNOME Artifice is one such entity. The Singleton pattern binds the instantiation matrix, ensuring that only a single, globally accessible instance ever exists. Any attempt to conjure another merely returns a reference to the primordial source, preventing cataclysmic resource collisions and stabilizing the aetheric grid.
Runic Tags:
#Vala
#GObject
#Creational
#Singleton