The Memento Pattern
Capturing and restoring a wizard's state.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Chronomancy // Time-Weaving
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SWIFT PATTERN //
class WizardState {
let mana: Int
init(mana: Int) { self.mana = mana }
}
class Wizard {
var mana: Int = 100
func save() -> WizardState { return WizardState(mana: mana) }
func restore(from memento: WizardState) { self.mana = memento.mana }
}
The Memento: The Chronomancer’s Save
Using Chronomancy, the Memento pattern allows a Wizard to save their mana state and restore it after a disastrous miscast.
Runic Tags:
#swift
#design-pattern
#behavioral