Memento: The Time-Twisting Sigil
Capture and externalize an object's internal state so it can be restored later.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Chronomancy // Time
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RPG PATTERN //
**FREE
Ctl-Opt NoMain;
Dcl-Ds State_t Qualified Template;
RecordId Int(10);
Value Char(50);
End-Ds;
Dcl-Proc CreateMemento Export;
Dcl-Pi *N Pointer;
pCurrentState Pointer Value;
End-Pi;
Dcl-S pMemento Pointer;
Dcl-Ds Current Likeds(State_t) Based(pCurrentState);
Dcl-Ds Memento Likeds(State_t) Based(pMemento);
pMemento = %Alloc(%Size(State_t));
Memento = Current; // Snapshot
Return pMemento;
End-Proc;
Dcl-Proc RestoreMemento Export;
Dcl-Pi *N;
pCurrentState Pointer Value;
pMemento Pointer Value;
End-Pi;
// ... copy back
End-Proc;
Memento
Often required during massive DB2 update transactions or interactive record editing, the Memento pattern safely stashes a memory-copy of the data structure. If the user cancels the spell, the original state is instantaneously restored.
Runic Tags:
#behavioral
#ibm-i
#runes
#memento