⚙️ C++ SPELL DIFFICULTY: Adept Behavioral

The Chain of Responsibility

Passing a spell request along a chain of warding nodes.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Abjuration // Warding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// EXECUTABLE C++ PATTERN //
#include <memory>
class Ward {
protected: std::shared_ptr<Ward> next;
public:
    virtual ~Ward() = default;
    void SetNext(std::shared_ptr<Ward> n) { next = n; }
    virtual void Handle(int power) {
        if(next) next->Handle(power);
    }
};
class FireWard : public Ward {
public:
    void Handle(int power) override {
        if(power < 10) {} // Handled
        else if(next) next->Handle(power);
    }
};
Runic Tags: #behavioral #chain-of-responsibility #cpp