The memento design pattern

Depending on the software we are writing, we might have a requirement to be able to restore the state of an object back to its previous state. The purpose of the memento design pattern is to:

Note

Provide the ability to execute an undo action in order to restore an object to a previous state.

The original memento design pattern is implemented with the help of three main objects:

  • Originator: The object whose state we want to be able to restore
  • Caretaker: The object that triggers the changes to the originator object and uses the memento objects for rollback, if needed
  • Memento: The object that carries the actual state of the originator and can be used to restore to one of the previous states

It is important to know that the memento ...

Get Scala Design Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.