Expand description

The Memento design pattern example module

In this exercise, the Memento pattern is used to take snapshots of a text object so as to form an undo list of changes to the text object. Undoing an operation means restoring a snapshot of the text object.

The undo list is implemented as a stack of memento objects that each represent a snapshot of the text object taken before each operation is applied. After all operations are applied, the mementos are used to restore the text object in reverse order, effectively undoing each operation in turn.

Accessed through the memento_exercise() function.

Modules

  • Contains the MementoTextObject struct that contains the text to be managed. Also contain the Memento struct that represents the snapshot of the text object for later restoration.

Structs

  • This struct creates a context around the undo list that the memento_exercise() executes within. This gets around the problem of needing a static undo list as all the methods on this context have ready access to the undo list in the context.

Functions