The Singleton Nexus Registry
Ensure a single, globally accessible instance of the social graph nexus.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // State Confinement
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// HACK PATTERN //
<?hh // strict
namespace SocialGraphAlchemy\Singleton;
final class NexusRegistry {
private static ?NexusRegistry $instance = null;
private dict<string, string> $nodes = dict[];
private function __construct() {}
public static function getInstance(): NexusRegistry {
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance as nonnull;
}
public function registerNode(string $id, string $address): void {
$this->nodes[$id] = $address;
}
public function resolveAddress(string $id): ?string {
return \HH\global_get('HH\Lib\Dict\idx')($this->nodes, $id);
}
}
The Absolute Point of Convergence
In a decentralized web, occasionally a supreme source of truth is required—a singular registry where every thread is logged. The Singleton pattern ensures that the Nexus Registry exists exactly once across the runtime, preventing temporal fracturing of node addresses.
Hack’s final class modifier ensures that rogue enchanters cannot extend the Singleton to bypass its isolation wards.
Runic Tags:
#hack
#singleton
#creational
#social-graph