🏛️ DELPHI ORACLE DIFFICULTY: Apprentice Behavioral

Command Scrolls

Encapsulating spells into scrolls for delayed casting or undoing.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Enchantment // Spell Storing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// DELPHI PATTERN //
unit CommandScrolls;

interface

type
  ISpellCommand = interface
    procedure Execute;
    procedure Undo;
  end;

  TLeyLine = class
  public
    procedure Surge;
    procedure Calm;
  end;

  TSurgeScroll = class(TInterfacedObject, ISpellCommand)
  private
    FLeyLine: TLeyLine;
  public
    constructor Create(LeyLine: TLeyLine);
    procedure Execute;
    procedure Undo;
  end;

implementation

uses System.SysUtils;

procedure TLeyLine.Surge;
begin
  Writeln('The ley line surges with crackling blue energy!');
end;

procedure TLeyLine.Calm;
begin
  Writeln('The ley line returns to a peaceful hum.');
end;

constructor TSurgeScroll.Create(LeyLine: TLeyLine);
begin
  FLeyLine := LeyLine;
end;

procedure TSurgeScroll.Execute;
begin
  FLeyLine.Surge;
end;

procedure TSurgeScroll.Undo;
begin
  FLeyLine.Calm;
end;

end.

A spell need not be cast immediately upon invocation. By sealing the magic within a TSurgeScroll, the Archmage can build a queue of spells, casting them at the opportune moment, or reversing them if the weave goes awry.

Runic Tags: #delphi #gof #behavioral #enchantment #command