The Chain of Responsibility Sequence
Passing requests along a chain of magical handlers.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Divination // Escalation Protocols
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CSHARP PATTERN //
using System;
namespace EnterpriseEvocation
{
public class Hex
{
public int Severity { get; }
public Hex(int severity) => Severity = severity;
}
public abstract class Dispeller
{
protected Dispeller Next;
public void SetNext(Dispeller next) => Next = next;
public abstract void Handle(Hex hex);
}
public class AcolyteDispeller : Dispeller
{
public override void Handle(Hex hex)
{
if (hex.Severity <= 10)
Console.WriteLine("Acolyte dispelled the minor hex.");
else
Next?.Handle(hex);
}
}
public class HighPriestDispeller : Dispeller
{
public override void Handle(Hex hex)
{
if (hex.Severity <= 50)
Console.WriteLine("High Priest dispelled the major curse.");
else
Next?.Handle(hex);
}
}
}
When a curse strikes the enterprise, the exact responder is often unknown. By establishing an escalation protocol, a minor acolyte attempts a dispel first; if the ward holds, the request gracefully falls through to the High Priest.
Runic Tags:
#behavioral
#chain-of-responsibility
#csharp