Visitor of the Spirit Realm
An inspector spirit that extracts mana from disparate magical artifacts.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Divination // Spirit Inspection
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// DELPHI PATTERN //
unit VisitorSpirits;
interface
type
TCrystal = class;
TScroll = class;
ISpiritVisitor = interface
procedure VisitCrystal(Crystal: TCrystal);
procedure VisitScroll(Scroll: TScroll);
end;
IArtifact = interface
procedure Accept(Visitor: ISpiritVisitor);
end;
TCrystal = class(TInterfacedObject, IArtifact)
public
procedure Accept(Visitor: ISpiritVisitor);
function GetMana: Integer;
end;
TScroll = class(TInterfacedObject, IArtifact)
public
procedure Accept(Visitor: ISpiritVisitor);
function GetSpellCasts: Integer;
end;
TManaHarvester = class(TInterfacedObject, ISpiritVisitor)
public
procedure VisitCrystal(Crystal: TCrystal);
procedure VisitScroll(Scroll: TScroll);
end;
implementation
uses System.SysUtils;
procedure TCrystal.Accept(Visitor: ISpiritVisitor);
begin
Visitor.VisitCrystal(Self);
end;
function TCrystal.GetMana: Integer;
begin
Result := 500;
end;
procedure TScroll.Accept(Visitor: ISpiritVisitor);
begin
Visitor.VisitScroll(Self);
end;
function TScroll.GetSpellCasts: Integer;
begin
Result := 3;
end;
procedure TManaHarvester.VisitCrystal(Crystal: TCrystal);
begin
Writeln(Format('Harvester extracted %d mana from the crystal.', [Crystal.GetMana]));
end;
procedure TManaHarvester.VisitScroll(Scroll: TScroll);
begin
Writeln(Format('Harvester consumed %d casts from the scroll.', [Scroll.GetSpellCasts]));
end;
end.
When traversing an array of mixed artifacts, an internal method on each would pollute their pure code. Instead, the Spirit Visitor is accepted into the artifact, extracting the necessary magic while maintaining structural wards.
Runic Tags:
#delphi
#gof
#behavioral
#divination
#visitor