The Singleton
The single immutable dark grimoire on the blockchain, eternally singular.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Warding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// IMMUTABLE DECENTRALIZED PACT //
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract DarkGrimoire {
address private staticInstance;
// In Solidity, contracts are inherently singletons if only deployed once.
// To enforce this within another contract system:
bool private initialized;
function init() public {
require(!initialized, "The Grimoire is already bound to this realm.");
initialized = true;
staticInstance = address(this);
}
function readSecrets() public view returns (string memory) {
require(initialized, "Grimoire uninitialized.");
return "Arcane secrets of the deep ledger.";
}
}
In the physical realm, a singleton restricts instantiation. In the decentralized void, a smart contract is inherently a singleton once deployed to an address. We enforce initialization locks to prevent the rewriting of the fundamental rules of the Dark Grimoire.
Runic Tags:
#solidity
#creational
#singleton