The Memento of the Phylactery
Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Necromancy // Time Reversal
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// FOXPRO PATTERN //
DEFINE CLASS Phylactery AS Custom
State = ""
PROCEDURE Init(cState)
THIS.State = cState
ENDPROC
FUNCTION GetState()
RETURN THIS.State
ENDFUNC
ENDDEFINE
DEFINE CLASS Lich AS Custom
CurrentPower = "Weakened"
FUNCTION SaveToPhylactery()
RETURN CREATEOBJECT("Phylactery", THIS.CurrentPower)
ENDFUNC
PROCEDURE RestoreFromPhylactery(oPhylactery)
THIS.CurrentPower = oPhylactery.GetState()
? "Lich power restored to: " + THIS.CurrentPower
ENDPROC
PROCEDURE GainPower()
THIS.CurrentPower = "Godlike"
ENDPROC
ENDDEFINE
The Lich hides its soul in a Phylactery (the Memento) to survive catastrophic failure. When its physical form is annihilated in memory, the master object can simply restore the precise configuration of its dark essence from the saved crystal.
Runic Tags:
#behavioral
#memento
#state
#undo