The Memento
Without violating encapsulation, capture and externalize an object's internal state so that it can be restored later.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Abjuration // Chronomancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ISABELLE PATTERN //
theory Memento
imports Main
begin
type_synonym memento = "nat * nat"
record wizard_state =
health :: nat
mana :: nat
definition save_state :: "wizard_state \<Rightarrow> memento" where
"save_state st = (health st, mana st)"
definition restore_state :: "memento \<Rightarrow> wizard_state" where
"restore_state m = \<lparr> health = fst m, mana = snd m \<rparr>"
end
Runic Tags:
#isabelle
#hol
#abjuration
#design-patterns