⚙️ ALLOY RUNE DIFFICULTY: Apprentice Creational

The Singleton: The Solitary Node

Ensure a class only has one instance, and provide a global point of access.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Singularity
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ALLOY PATTERN //
one sig TheNexus {
  activeConnections: set Node
}

sig Node {}

pred connect[n: Node] {
  n in TheNexus.activeConnections
}

run connect for 3

The Singleton: The Solitary Node

The Singleton is arguably the most elegant pattern in Alloy. By prefixing a signature with the one multiplicity keyword, we command the Alloy Analyzer to generate exactly one atom of this sigil in every possible universe. TheNexus stands alone, unparalleled, an unbreakable singularity.

Runic Tags: #creational #singleton #oneness