⛓️ SOLIDITY PACTS DIFFICULTY: Adept Creational

The Factory Method

Delegating the instantiation of soul contracts to specialized demon princes.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Summoning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// IMMUTABLE DECENTRALIZED PACT //
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ISoulContract {
    function extract() external returns (string memory);
}

contract WrathContract is ISoulContract {
    function extract() external pure override returns (string memory) {
        return "Wrath consumed.";
    }
}

contract GreedContract is ISoulContract {
    function extract() external pure override returns (string memory) {
        return "Greed hoarded.";
    }
}

abstract contract DemonPrince {
    function summonContract() public virtual returns (ISoulContract);

    function executeTithe() public returns (string memory) {
        ISoulContract soulContract = summonContract();
        return soulContract.extract();
    }
}

contract PrinceOfWrath is DemonPrince {
    function summonContract() public pure override returns (ISoulContract) {
        return new WrathContract();
    }
}

contract PrinceOfGreed is DemonPrince {
    function summonContract() public pure override returns (ISoulContract) {
        return new GreedContract();
    }
}

The Factory Method allows a base contract to define the ritual for summoning, while leaving the exact manifestation of the soul contract to the specialized demon princes. This polymorphism is key when building vast networks of infernal ledgers.

Runic Tags: #solidity #creational #factory-method