🔴 SCALA ALCHEMY DIFFICULTY: Apprentice Behavioral

The Memento Crystal

Capture a snapshot of an artifact's state so it can be restored if an experiment goes disastrously wrong.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Chronomancy // Time Reversal
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCALA PATTERN //
case class TimeCrystal(state: String) // The Memento

class AlchemistFlask {
  private var potionColor: String = "Clear"

  def addIngredient(color: String): Unit = potionColor = color
  def save(): TimeCrystal = TimeCrystal(potionColor)
  def restore(crystal: TimeCrystal): Unit = potionColor = crystal.state
  def current: String = potionColor
}

Using a case class as an immutable token, the Memento pattern allows the pure preservation of state without violating encapsulation. True Chronomancy in practice.

Runic Tags: #scala #behavioral #chronomancy #state-saving