7
← Back to Pattern Arsenal
behavioral

Memento

good to-know

Stage 1: Problem

Problem

You are building a configuration editor for a deployment pipeline. Users tweak YAML configs — change environment variables, toggle feature flags, adjust replica counts. They need to undo their last 10 changes and redo if they undo too far. The config object has nested state: environment map, feature flags, scaling rules, secrets references.

Saving and restoring this state is tricky. You do not want to expose every internal field via public getters just so an undo system can snapshot it. And you do not want the undo system to know the internal structure of the config object — that would couple them tightly.

Before continuing, think: how would you save and restore an object's state without breaking encapsulation?

1 / 10 — Problem