The Memento of State Preservation
Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored later in Move.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Divination // Chronomancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module arcane::memento {
struct State has store, copy, drop {
mana: u64,
health: u64,
}
struct Memento has store, drop {
state: State,
}
public fun save(state: &State): Memento {
Memento { state: *state }
}
public fun restore(memento: &Memento): State {
*&memento.state
}
}
Runic Tags:
#behavioral
#memento
#move
#state-management