The Singleton of the Global State Matrix
Ensure that a given resource pool has only one instance, and provide a universal point of contact to it.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Sysadmin Telepathy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// POWERSHELL PATTERN //
class MasterConfig {
static [MasterConfig] $_instance
[hashtable] $Settings
hidden MasterConfig() {
$this.Settings = @{
"MaxConnections" = 100
"Timeout" = 30
}
Write-Host "MasterConfig Matrix Initialized." -ForegroundColor Magenta
}
static [MasterConfig] GetInstance() {
if ($null -eq [MasterConfig]::_instance) {
[MasterConfig]::_instance = [MasterConfig]::new()
}
return [MasterConfig]::_instance
}
}
# Channeling the singularity
$config1 = [MasterConfig]::GetInstance()
$config2 = [MasterConfig]::GetInstance()
if ([object]::ReferenceEquals($config1, $config2)) {
Write-Host "The State Matrix is singular and unbroken."
}
A classic ward against chaos. The Singleton pattern ensures that across the myriad threads of sysadmin telepathy, there exists only one immutable source of truth for global configuration.
Runic Tags:
#powershell
#sysadmin
#creational
#singleton
#configuration