Memento Pattern

The Memento pattern preserves a “snapshot” of an object’s state, so that the object can return to its original state without having to reveal its content to the rest of the world. 

UML Representation

Benefits

The following lists the benefits of using the Memento pattern:
  • Preserves encapsulation boundaries 
  • Simplifies the originator
  • The individual components become simpler and easier to deal with, because they no longer need to directly pass messages to each other.
  • Components are more generic, because they no longer need to contain logic to deal with their communication with other components.

When to Use

You should use the Memento pattern when:
  • A snapshot of an object’s state must be saved so that it can be restored to that state later.
  • Using a direct interface to obtain the state would expose implementation details and break the object’s encapsulation.
Subpages (1): Memento Pattern Example
Comments