🦊 FOXPRO APPARITION DIFFICULTY: Adept Behavioral

The Command of the Sealed Scroll

Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Transmutation // Rune Sealing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FOXPRO PATTERN //
DEFINE CLASS Command AS Custom
    PROCEDURE Execute()
    ENDPROC
ENDDEFINE

DEFINE CLASS PurgeTableCommand AS Command
    cTableName = ""

    PROCEDURE Init(cName)
        THIS.cTableName = cName
    ENDPROC

    PROCEDURE Execute()
        ? "ZAPping the cursed table: " + THIS.cTableName
    ENDPROC
ENDDEFINE

DEFINE CLASS Invoker AS Custom
    DIMENSION aSpells[1]
    nSpellCount = 0

    PROCEDURE StoreSpell(oCmd)
        THIS.nSpellCount = THIS.nSpellCount + 1
        DIMENSION THIS.aSpells[THIS.nSpellCount]
        THIS.aSpells[THIS.nSpellCount] = oCmd
    ENDPROC

    PROCEDURE Unleash()
        LOCAL i
        FOR i = 1 TO THIS.nSpellCount
            THIS.aSpells[i].Execute()
        ENDFOR
    ENDPROC
ENDDEFINE

A Command is a spell sealed inside a scroll. It can be handed to an acolyte, stored in a dusty archive, or queued for a grand ritual later. The execution is perfectly decoupled from its utterance.

Runic Tags: #behavioral #command #encapsulation #invocation