The Singleton Nexus
A singular focal point of magical power, universally accessible but strictly controlled.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Monolithic Leylines
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CSHARP PATTERN //
using System;
namespace EnterpriseEvocation
{
public sealed class LeylineNexus
{
private static readonly Lazy<LeylineNexus> _instance =
new Lazy<LeylineNexus>(() => new LeylineNexus());
public static LeylineNexus Instance => _instance.Value;
private int _manaReserves;
private LeylineNexus()
{
_manaReserves = 10000;
Console.WriteLine("The singular Leyline Nexus has been awakened.");
}
public void Tap(int amount)
{
if (_manaReserves >= amount)
{
_manaReserves -= amount;
Console.WriteLine($"Tapped {amount} mana. {_manaReserves} remaining.");
}
else
{
Console.WriteLine("Insufficient mana in the Nexus!");
}
}
}
}
The Singleton pattern guarantees that only one instance of a crucial resource exists within the enterprise application domain. Using .NET’s Lazy<T>, the LeylineNexus ensures thread-safe, thread-locked initialization of the global mana reserves.
Runic Tags:
#creational
#singleton
#thread-safety
#csharp