🎸 GROOVY HEX DIFFICULTY: Apprentice Creational

The Singleton Hex

Ensuring only one instance of an ancient nexus exists in the runtime.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Conjuration // Singularism
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GROOVY PATTERN //
@Singleton
class NexusCore {
    int energy = 100

    def tap() {
        energy -= 10
        println "Nexus tapped. Energy remaining: $energy"
    }
}

NexusCore.instance.tap()
NexusCore.instance.tap()

// def duplicate = new NexusCore() // This would trigger a runtime hex-breach (Exception)

The Singleton Hex

A Singleton dictates that a magical construct must be singular and unique across the entire JVM continuum. Groovy encapsulates the tedious locking and instantiation checks behind the @Singleton AST annotation. Access the single nexus via .instance, knowing the thread-safe magic holds firm.

Runic Tags: #groovy #creational #singleton #ast-transform