Platinum Partner
architects,enterprise-integration,patterns

The Memento Pattern

Description:

The Memento captures and externalizes an object’s internal state so that the object can later be restored to that state. Command can use Memento to maintain the state required for an undo operation. It lets you capture an object’s state so you can restore the object later, so it's very useful for an undo operation.

Without violating encapsulation,capture and externalize an object’s internal state so the the object can be restored to this state later.

Benefits:

Provides easy to implement recovery capability.

When to use:

  •  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

Diagram:

Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}