The Strategy
Swapping combat algorithms in the eternal Blood War.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Divination // Tactics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// IMMUTABLE DECENTRALIZED PACT //
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ICombatStrategy {
function executeTactic(uint256 enemyForces) external pure returns (string memory);
}
contract AggressiveAssault is ICombatStrategy {
function executeTactic(uint256 enemyForces) external pure override returns (string memory) {
return "Charge blindly into the fray!";
}
}
contract TacticalRetreat is ICombatStrategy {
function executeTactic(uint256 enemyForces) external pure override returns (string memory) {
return "Fall back to the abyssal trenches.";
}
}
contract BloodWarGeneral {
ICombatStrategy public strategy;
function setStrategy(address _strategy) external {
strategy = ICombatStrategy(_strategy);
}
function faceEnemy(uint256 enemyForces) external view returns (string memory) {
return strategy.executeTactic(enemyForces);
}
}
In the eternal Blood War, tactics must adapt to the tides of battle. The Strategy pattern defines a family of combat algorithms as separate smart contracts, allowing the Blood War General to hot-swap tactical algorithms at runtime without redeploying the core command logic.
Runic Tags:
#solidity
#behavioral
#strategy