jargon

Comparison

Command patternvsMemento pattern

Command pattern

the request became an object with an execute method, so you could put it in a queue, log it and undo it.

Turning an invocation into a first-class object carrying its receiver and arguments, so it can be stored, passed, queued, retried, logged or reversed. That reification is the point — a strategy and a command can be identical in shape, and the difference is that a strategy is how to do something and a command is a particular thing to do. It is the object-level relative of every persisted-request idea, from job queues to event sourcing.

Full entry →

Memento pattern

the object handed out an opaque snapshot of itself that only it can read, and later took it back to undo.

Capturing an object's internal state in a form something else can hold but not inspect, so it can be restored later. The encapsulation constraint is what distinguishes it from just copying the fields — the caretaker gets a token, not the data. Almost nobody names it in production code, but it is the honest description of every undo stack and editor snapshot, and it is asked about.

Full entry →

Related comparisons