Memento: Movie Night, Then Back to Normal
When movie night saves each light's brightness itself, by reading the light's fields, then puts them back, it breaks the day the lights gain a color setting; a Memento lets each light make a snapshot of its own state and restore from it, while movie night only holds the snapshots.
Journeyman · OOP · Updated
After this lesson you can
- Let an object save a snapshot of its own state and put it back later, without others reading it
- Spot the smells that point to Memento: code outside an object copying its fields to restore them later
Key takeaways
- The smell: code outside an object copies the object's fields so it can put them back later, and must change whenever the object gains a field.
- The cause: the saving lives outside the object that knows what its state is.
- The fix: the object makes its own snapshot (a memento) and restores from it; the code that holds the snapshots (the caretaker) never looks inside.
- The modern version: save hands back a function that puts things back.
- Skip it when the state is one public value, or so big that copying it is too slow.
Before this: Meet the Smart-Home Hub, and encapsulation (an object keeping its own data private).
Friday is movie night at Maya's. The living room dims to 20% and turns blue, the kitchen lights go off, and when the movie ends, every light should go back exactly as it was: the living room at 80%, the kitchen at 100%, the bedroom at 40%, all warm white. The examples' RoomLight is the hub's own class for a room's light (behind it, a LumoLightAdapter). The movie-night routine was written last year, when Lumo lights had only a brightness. This month they got a color. This lesson's pattern, Memento, is about putting things back the way they were.
The symptom: back to 80%, and still blue
The routine remembers each light's brightness itself, then puts it back:
List<RoomLight> lights = new List<RoomLight>
{
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"),
};
// Written last year, before the lights had a color.
Dictionary<string, int> saved = lights.ToDictionary(light => light.Room, light => light.Brightness);
lights[0].Set(20, "blue");
lights[1].Set(0, "warm white");
Show("Movie on:", lights);
foreach (RoomLight light in lights)
{
light.Brightness = saved[light.Room];
}
Show("Movie over:", lights);
void Show(string heading, List<RoomLight> all)
{
Console.WriteLine(heading);
foreach (RoomLight light in all)
{
Console.WriteLine( quot;{light.Room}: {light.Brightness}%, {light.Color}");
}
}
class RoomLight
{
public string Room { get; }
public int Brightness { get; set; }
public string Color { get; set; } // new this month
public RoomLight(string room, int brightness, string color)
{
Room = room;
Brightness = brightness;
Color = color;
}
public void Set(int brightness, string color)
{
Brightness = brightness;
Color = color;
}
}
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, blue
Kitchen: 100%, warm white
Bedroom: 40%, warm white
class RoomLight {
final String room;
int brightness;
String color; // new this month
RoomLight(String room, int brightness, String color) {
this.room = room;
this.brightness = brightness;
this.color = color;
}
void set(int brightness, String color) {
this.brightness = brightness;
this.color = color;
}
}
void show(String heading, List<RoomLight> lights) {
IO.println(heading);
for (RoomLight light : lights) {
IO.println(light.room + ": " + light.brightness + "%, " + light.color);
}
}
void main() {
List<RoomLight> lights = List.of(
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"));
// Written last year, before the lights had a color.
Map<String, Integer> saved = new HashMap<>();
for (RoomLight light : lights) {
saved.put(light.room, light.brightness);
}
lights.get(0).set(20, "blue");
lights.get(1).set(0, "warm white");
show("Movie on:", lights);
for (RoomLight light : lights) {
light.brightness = saved.get(light.room);
}
show("Movie over:", lights);
}
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, blue
Kitchen: 100%, warm white
Bedroom: 40%, warm white
class RoomLight:
def __init__(self, room, brightness, color):
self.room = room
self.brightness = brightness
self.color = color # new this month
def set(self, brightness, color):
self.brightness = brightness
self.color = color
def show(heading, lights):
print(heading)
for light in lights:
print(f"{light.room}: {light.brightness}%, {light.color}")
lights = [
RoomLight("Living room", 80, "warm white"),
RoomLight("Kitchen", 100, "warm white"),
RoomLight("Bedroom", 40, "warm white"),
]
# Written last year, before the lights had a color.
saved = {light.room: light.brightness for light in lights}
lights[0].set(20, "blue")
lights[1].set(0, "warm white")
show("Movie on:", lights)
for light in lights:
light.brightness = saved[light.room]
show("Movie over:", lights)
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, blue
Kitchen: 100%, warm white
Bedroom: 40%, warm white
class RoomLight {
constructor(room, brightness, color) {
this.room = room;
this.brightness = brightness;
this.color = color; // new this month
}
set(brightness, color) {
this.brightness = brightness;
this.color = color;
}
}
function show(heading, lights) {
console.log(heading);
for (const light of lights) console.log(`${light.room}: ${light.brightness}%, ${light.color}`);
}
const lights = [
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"),
];
// Written last year, before the lights had a color.
const saved = new Map(lights.map((light) => [light.room, light.brightness]));
lights[0].set(20, "blue");
lights[1].set(0, "warm white");
show("Movie on:", lights);
for (const light of lights) light.brightness = saved.get(light.room);
show("Movie over:", lights);
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, blue
Kitchen: 100%, warm white
Bedroom: 40%, warm white
class RoomLight {
room: string;
brightness: number;
color: string; // new this month
constructor(room: string, brightness: number, color: string) {
this.room = room;
this.brightness = brightness;
this.color = color;
}
set(brightness: number, color: string): void {
this.brightness = brightness;
this.color = color;
}
}
function show(heading: string, lights: RoomLight[]): void {
console.log(heading);
for (const light of lights) console.log(`${light.room}: ${light.brightness}%, ${light.color}`);
}
const lights = [
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"),
];
// Written last year, before the lights had a color.
const saved = new Map(lights.map((light) => [light.room, light.brightness]));
lights[0].set(20, "blue");
lights[1].set(0, "warm white");
show("Movie on:", lights);
for (const light of lights) light.brightness = saved.get(light.room)!;
show("Movie over:", lights);
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, blue
Kitchen: 100%, warm white
Bedroom: 40%, warm white
The living room came back to 80%, and stayed blue. Nobody touched movie night; the light changed under it. And there's more coming: Lumo's next update adds a "fade time", and the bedtime routine and the party scene save and restore lights the same way, each with its own copy of "which fields does a light have?".
- The symptom: code outside an object copies the object's fields so it can put them back later, and quietly breaks whenever the object gains a field.
- The cause: the saving lives outside the light, in every routine that needs it, and only the light really knows what its state is. To do it at all, the light had to make its fields public.
What would you try?
Add the color to movie night's copy. It fixes Friday. The bedtime routine and the party scene still forget it, and the fade time will break all three next month.
Save whole copies of the lights. Copy each RoomLight object, then swap the copies back in. But other parts of the hub hold the original light objects; swapping in copies leaves them pointing at lights that are no longer in use.
Never change the lights for a scene; make new "scene lights" instead. The real bulbs still have to change. Something has to put them back.
What we want is for the light to save itself, since it knows its own fields, and for the routine to keep the result without needing to understand it.
The fix: let the light take its own snapshot
A video game's save point works this way. Before the hard level, the game saves your progress: your position, your health, what you're carrying. You don't write any of that down, and you couldn't read the save file if you tried. Fail the level, and you're put back exactly where you were. Only the game understands the save.

So the light gets two methods. save() makes a snapshot of everything the light needs to come back exactly as it is, and hands it over. restore(snapshot) puts the light back from it. The routine keeps the snapshots and hands them back later, without ever reading inside. When Lumo adds the fade time, only RoomLight's own save and restore change.

The classic version: a snapshot only the light can read
The snapshot's contents are private to the light. Everyone else sees an empty promise, Snapshot, that they can hold and hand back, but not open:
List<RoomLight> lights = new List<RoomLight>
{
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"),
};
List<ISnapshot> snapshots = lights.Select(light => light.Save()).ToList(); // movie night holds these, unopened
lights[0].Set(20, "blue");
lights[1].Set(0, "warm white");
Show("Movie on:", lights);
for (int i = 0; i < lights.Count; i++)
{
lights[i].Restore(snapshots[i]);
}
Show("Movie over:", lights);
void Show(string heading, List<RoomLight> all)
{
Console.WriteLine(heading);
foreach (RoomLight light in all)
{
Console.WriteLine(light.Describe());
}
}
interface ISnapshot { } // something you can hold and hand back, but not open
class RoomLight
{
private readonly string room;
private int brightness;
private string color;
public RoomLight(string room, int brightness, string color)
{
this.room = room;
this.brightness = brightness;
this.color = color;
}
public void Set(int brightness, string color)
{
this.brightness = brightness;
this.color = color;
}
public string Describe() => quot;{room}: {brightness}%, {color}";
public ISnapshot Save() => new LightSnapshot(brightness, color);
public void Restore(ISnapshot snapshot)
{
LightSnapshot saved = (LightSnapshot)snapshot;
brightness = saved.Brightness;
color = saved.Color;
}
// Private: only RoomLight can see what's inside.
private record LightSnapshot(int Brightness, string Color) : ISnapshot;
}
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, warm white
Kitchen: 100%, warm white
Bedroom: 40%, warm white
interface Snapshot { } // something you can hold and hand back, but not open
class RoomLight {
private final String room;
private int brightness;
private String color;
// Private: only RoomLight can see what's inside.
private record LightSnapshot(int brightness, String color) implements Snapshot { }
RoomLight(String room, int brightness, String color) {
this.room = room;
this.brightness = brightness;
this.color = color;
}
void set(int brightness, String color) {
this.brightness = brightness;
this.color = color;
}
String describe() { return room + ": " + brightness + "%, " + color; }
Snapshot save() { return new LightSnapshot(brightness, color); }
void restore(Snapshot snapshot) {
LightSnapshot saved = (LightSnapshot) snapshot;
brightness = saved.brightness();
color = saved.color();
}
}
void show(String heading, List<RoomLight> lights) {
IO.println(heading);
for (RoomLight light : lights) {
IO.println(light.describe());
}
}
void main() {
List<RoomLight> lights = List.of(
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"));
List<Snapshot> snapshots = new ArrayList<>(); // movie night holds these, unopened
for (RoomLight light : lights) {
snapshots.add(light.save());
}
lights.get(0).set(20, "blue");
lights.get(1).set(0, "warm white");
show("Movie on:", lights);
for (int i = 0; i < lights.size(); i++) {
lights.get(i).restore(snapshots.get(i));
}
show("Movie over:", lights);
}
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, warm white
Kitchen: 100%, warm white
Bedroom: 40%, warm white
class LightSnapshot:
"""A snapshot of one light. Only RoomLight reads what's inside (the leading _ says so)."""
def __init__(self, brightness, color):
self._brightness = brightness
self._color = color
class RoomLight:
def __init__(self, room, brightness, color):
self._room = room
self._brightness = brightness
self._color = color
def set(self, brightness, color):
self._brightness = brightness
self._color = color
def describe(self):
return f"{self._room}: {self._brightness}%, {self._color}"
def save(self):
return LightSnapshot(self._brightness, self._color)
def restore(self, snapshot):
self._brightness = snapshot._brightness
self._color = snapshot._color
def show(heading, lights):
print(heading)
for light in lights:
print(light.describe())
lights = [
RoomLight("Living room", 80, "warm white"),
RoomLight("Kitchen", 100, "warm white"),
RoomLight("Bedroom", 40, "warm white"),
]
snapshots = [light.save() for light in lights] # movie night holds these, unopened
lights[0].set(20, "blue")
lights[1].set(0, "warm white")
show("Movie on:", lights)
for light, snapshot in zip(lights, snapshots):
light.restore(snapshot)
show("Movie over:", lights)
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, warm white
Kitchen: 100%, warm white
Bedroom: 40%, warm white
class RoomLight {
#room;
#brightness;
#color;
constructor(room, brightness, color) {
this.#room = room;
this.#brightness = brightness;
this.#color = color;
}
set(brightness, color) {
this.#brightness = brightness;
this.#color = color;
}
describe() { return `${this.#room}: ${this.#brightness}%, ${this.#color}`; }
// A frozen snapshot: it can't be changed, and only the light reads it.
save() { return Object.freeze({ brightness: this.#brightness, color: this.#color }); }
restore(snapshot) {
this.#brightness = snapshot.brightness;
this.#color = snapshot.color;
}
}
function show(heading, lights) {
console.log(heading);
for (const light of lights) console.log(light.describe());
}
const lights = [
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"),
];
const snapshots = lights.map((light) => light.save()); // movie night holds these, unopened
lights[0].set(20, "blue");
lights[1].set(0, "warm white");
show("Movie on:", lights);
lights.forEach((light, i) => light.restore(snapshots[i]));
show("Movie over:", lights);
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, warm white
Kitchen: 100%, warm white
Bedroom: 40%, warm white
// A frozen snapshot: it can't be changed, and only the light reads it.
type LightSnapshot = Readonly<{ brightness: number; color: string }>;
class RoomLight {
#room: string;
#brightness: number;
#color: string;
constructor(room: string, brightness: number, color: string) {
this.#room = room;
this.#brightness = brightness;
this.#color = color;
}
set(brightness: number, color: string): void {
this.#brightness = brightness;
this.#color = color;
}
describe(): string { return `${this.#room}: ${this.#brightness}%, ${this.#color}`; }
save(): LightSnapshot { return Object.freeze({ brightness: this.#brightness, color: this.#color }); }
restore(snapshot: LightSnapshot): void {
this.#brightness = snapshot.brightness;
this.#color = snapshot.color;
}
}
function show(heading: string, lights: RoomLight[]): void {
console.log(heading);
for (const light of lights) console.log(light.describe());
}
const lights = [
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"),
];
const snapshots = lights.map((light) => light.save()); // movie night holds these, unopened
lights[0].set(20, "blue");
lights[1].set(0, "warm white");
show("Movie on:", lights);
lights.forEach((light, i) => light.restore(snapshots[i]));
show("Movie over:", lights);
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, warm white
Kitchen: 100%, warm white
Bedroom: 40%, warm white
Warm white again. Movie night no longer mentions brightness or color at all: it saves, holds and restores. The light's fields are private now, too, because nobody outside needs to read them. C# and Java can make the snapshot truly unreadable from outside, a private record nested inside the light, behind an empty Snapshot promise. Python, JavaScript and TypeScript can't hide it that well: the snapshot is frozen (or marked with _), and the routine never looks inside. The modern version below hides it completely, in every language.
The modern version: save hands back "put it back"
The routine only ever does one thing with a snapshot: hand it back. So save() can hand back that action itself, a function that remembers the old values and puts them back when it's called:
List<RoomLight> lights = new List<RoomLight>
{
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"),
};
List<Action> putBack = lights.Select(light => light.Save()).ToList();
lights[0].Set(20, "blue");
lights[1].Set(0, "warm white");
Show("Movie on:", lights);
putBack.ForEach(restore => restore());
Show("Movie over:", lights);
void Show(string heading, List<RoomLight> all)
{
Console.WriteLine(heading);
foreach (RoomLight light in all)
{
Console.WriteLine(light.Describe());
}
}
class RoomLight
{
private readonly string room;
private int brightness;
private string color;
public RoomLight(string room, int brightness, string color)
{
this.room = room;
this.brightness = brightness;
this.color = color;
}
public void Set(int brightness, string color)
{
this.brightness = brightness;
this.color = color;
}
public string Describe() => quot;{room}: {brightness}%, {color}";
// The snapshot is a function that remembers the old values and puts them back.
public Action Save()
{
int savedBrightness = brightness;
string savedColor = color;
return () =>
{
brightness = savedBrightness;
color = savedColor;
};
}
}
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, warm white
Kitchen: 100%, warm white
Bedroom: 40%, warm white
class RoomLight {
private final String room;
private int brightness;
private String color;
RoomLight(String room, int brightness, String color) {
this.room = room;
this.brightness = brightness;
this.color = color;
}
void set(int brightness, String color) {
this.brightness = brightness;
this.color = color;
}
String describe() { return room + ": " + brightness + "%, " + color; }
// The snapshot is a function that remembers the old values and puts them back.
Runnable save() {
int savedBrightness = brightness;
String savedColor = color;
return () -> {
brightness = savedBrightness;
color = savedColor;
};
}
}
void show(String heading, List<RoomLight> lights) {
IO.println(heading);
for (RoomLight light : lights) {
IO.println(light.describe());
}
}
void main() {
List<RoomLight> lights = List.of(
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"));
List<Runnable> putBack = new ArrayList<>();
for (RoomLight light : lights) {
putBack.add(light.save());
}
lights.get(0).set(20, "blue");
lights.get(1).set(0, "warm white");
show("Movie on:", lights);
putBack.forEach(Runnable::run);
show("Movie over:", lights);
}
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, warm white
Kitchen: 100%, warm white
Bedroom: 40%, warm white
class RoomLight:
def __init__(self, room, brightness, color):
self._room = room
self._brightness = brightness
self._color = color
def set(self, brightness, color):
self._brightness = brightness
self._color = color
def describe(self):
return f"{self._room}: {self._brightness}%, {self._color}"
def save(self):
"""The snapshot is a function that remembers the old values and puts them back."""
brightness, color = self._brightness, self._color
def restore():
self._brightness, self._color = brightness, color
return restore
def show(heading, lights):
print(heading)
for light in lights:
print(light.describe())
lights = [
RoomLight("Living room", 80, "warm white"),
RoomLight("Kitchen", 100, "warm white"),
RoomLight("Bedroom", 40, "warm white"),
]
put_back = [light.save() for light in lights]
lights[0].set(20, "blue")
lights[1].set(0, "warm white")
show("Movie on:", lights)
for restore in put_back:
restore()
show("Movie over:", lights)
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, warm white
Kitchen: 100%, warm white
Bedroom: 40%, warm white
class RoomLight {
#room;
#brightness;
#color;
constructor(room, brightness, color) {
this.#room = room;
this.#brightness = brightness;
this.#color = color;
}
set(brightness, color) {
this.#brightness = brightness;
this.#color = color;
}
describe() { return `${this.#room}: ${this.#brightness}%, ${this.#color}`; }
// The snapshot is a function that remembers the old values and puts them back.
save() {
const brightness = this.#brightness;
const color = this.#color;
return () => {
this.#brightness = brightness;
this.#color = color;
};
}
}
function show(heading, lights) {
console.log(heading);
for (const light of lights) console.log(light.describe());
}
const lights = [
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"),
];
const putBack = lights.map((light) => light.save());
lights[0].set(20, "blue");
lights[1].set(0, "warm white");
show("Movie on:", lights);
putBack.forEach((restore) => restore());
show("Movie over:", lights);
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, warm white
Kitchen: 100%, warm white
Bedroom: 40%, warm white
class RoomLight {
#room: string;
#brightness: number;
#color: string;
constructor(room: string, brightness: number, color: string) {
this.#room = room;
this.#brightness = brightness;
this.#color = color;
}
set(brightness: number, color: string): void {
this.#brightness = brightness;
this.#color = color;
}
describe(): string { return `${this.#room}: ${this.#brightness}%, ${this.#color}`; }
// The snapshot is a function that remembers the old values and puts them back.
save(): () => void {
const brightness = this.#brightness;
const color = this.#color;
return () => {
this.#brightness = brightness;
this.#color = color;
};
}
}
function show(heading: string, lights: RoomLight[]): void {
console.log(heading);
for (const light of lights) console.log(light.describe());
}
const lights = [
new RoomLight("Living room", 80, "warm white"),
new RoomLight("Kitchen", 100, "warm white"),
new RoomLight("Bedroom", 40, "warm white"),
];
const putBack = lights.map((light) => light.save());
lights[0].set(20, "blue");
lights[1].set(0, "warm white");
show("Movie on:", lights);
putBack.forEach((restore) => restore());
show("Movie over:", lights);
Movie on:
Living room: 20%, blue
Kitchen: 0%, warm white
Bedroom: 40%, warm white
Movie over:
Living room: 80%, warm white
Kitchen: 100%, warm white
Bedroom: 40%, warm white
Same output. The saved values live inside the function (a closure: a function that keeps the variables it was made with), where nothing but that function can reach them. Use the classic version when the snapshot needs to be stored somewhere (written to a file so a scene survives a restart, say), since a function can't be saved to disk; use the modern one when "put it back later, in this program" is all you need.
How it got its name
A memento is a keepsake that holds a memory, like a ticket stub from a concert. The object that makes it is the originator (the light), and the one that keeps it without opening it is the caretaker (movie night). Teams building undo buttons and "cancel" for forms kept hitting the same choice, expose the object's insides or lose the ability to put it back, and the way out went into the original 1994 book as the Memento pattern. Pass 2's undo button undid commands; a memento undoes by putting back a whole saved state, which is simpler when many things changed at once.
Where you've already used it
- Save points and saved games, and "Restore previous session" in a browser.
- Undo in a drawing app, which often saves a snapshot before each brush stroke.
- A database transaction that rolls back: the database keeps what it needs to put everything back, and you never read it.
When not to use it
- When the state is one public value. Saving
volumein a variable and setting it back is fine; a snapshot class for one number is ceremony. - When the state is huge. Snapshotting a whole photo before every brush stroke uses a lot of memory; record the change instead (Pass 2's Command), or save only what changed.
- When the outside world changed too. A snapshot restores the light, not the electricity used or the message already sent to Maya's phone.
The cost: every save keeps a copy, so snapshots that are never dropped pile up; keep only as many as you need (one, for movie night).
How often you'll meet it: now and then (our estimate: behind undo, cancel and "restore" buttons, often without the name).
Check yourself
2 questions to try on the lesson page.
So what
When other code copies an object's fields so it can put them back, let the object take its own snapshot instead. The routine holds it without reading it, the object's insides stay private, and a new setting changes one class, not every routine that saves.