Memento Pattern
noun
say it: “muh-MEN-toh PAT-urn” /məˈmɛntoʊ ˈpætərn/
A design pattern in which an object saves a snapshot of its own state, which others can hold but not read, and restores itself from it later.
What is the Memento pattern?
The Memento pattern lets an object save a snapshot of its own state (a memento) and restore from it later. The code that keeps the snapshot (the caretaker) holds it without reading inside. Movie night saves each light's snapshot before dimming the room, and hands them back afterwards, so a light's new color setting comes back too, without movie night knowing about colors.
In a sentence
- “Each light handed movie night a memento, and movie night handed them back without ever looking inside.”
Level: Journeyman · More OOP terms at this level
Updated