Decorator: The Layered Ward
Attach additional responsibilities to an RPG object dynamically.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Abjuration // Shield
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RPG PATTERN //
**FREE
Ctl-Opt NoMain;
Dcl-Ds Rune_t Qualified Template;
ExecutePtr Pointer(*Proc);
BaseRune Pointer; // Pointer to the wrapped Rune
End-Ds;
Dcl-Pr ExecBase ExtProc(Base.ExecutePtr);
End-Pr;
Dcl-Proc DecoratorRune Export;
Dcl-Pi *N;
pWrappedRune Pointer Value;
End-Pi;
Dcl-Ds Base Likeds(Rune_t) Based(pWrappedRune);
// Add additional logging magic before invocation
Dsply 'Invoking inner Ward...';
// Call the inner rune
ExecBase();
End-Proc;
Decorator
Often, modifying a stable Service Program is risky. The Decorator pattern in RPGLE allows adding new behaviors (like audit logging or authorization checks) by wrapping the original procedure pointer with a layered Ward.
Runic Tags:
#structural
#ibm-i
#runes
#decorator