⚔️ RPG WARD DIFFICULTY: Adept Behavioral

Chain of Responsibility: The Line of Wards

Pass a request along a chain of handlers until one resolves it.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Enchantment // Compulsion
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RPG PATTERN //
**FREE
Ctl-Opt NoMain;

Dcl-Ds Handler_t Qualified Template;
  ProcessProc Pointer(*Proc);
  NextHandler Pointer; // Pointer to next Handler_t
End-Ds;

Dcl-Proc ProcessChain Export;
  Dcl-Pi *N Ind;
    pHandler Pointer Value;
    RequestData Char(50) Const;
  End-Pi;

  Dcl-Ds Handler Likeds(Handler_t) Based(pHandler);
  Dcl-Pr RunProcess Ind ExtProc(Handler.ProcessProc);
    Data Char(50) Const;
  End-Pr;

  If pHandler = *Null;
     Return *Off; // Unhandled
  EndIf;

  If RunProcess(RequestData);
     Return *On; // Handled
  Else;
     Return ProcessChain(Handler.NextHandler: RequestData);
  EndIf;
End-Proc;

Chain of Responsibility

In RPGLE, a sequence of procedure pointers linked in a Data Structure list allows requests to be passed through a chain of processing wards. If a ward cannot process the data, it defers to the next until the end of the line.

Runic Tags: #behavioral #ibm-i #runes #chain-of-responsibility