Chapter    23

The Memento Pattern

The memento pattern is a close relative of the command pattern I described in Chapter 20, with the important difference that it is used to capture the complete state of an object so that it can be subsequently reset. Table 23-1 puts the memento pattern in context.

Table 23-1. Putting the Memento Pattern into Context

Question

Answer

What is it?

The memento pattern captures the complete state of an object into a memento that can be used to reset the object at a later date.

What are the benefits?

The memento pattern allows a complete reset of an object without the need to track and apply individual undo commands.

When should you use this pattern?

Use this pattern when there is a “known-good” point in an object’s life ...

Get Pro Design Patterns in Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.