Enterprise Integration Zone is brought to you in partnership with:

Cristian Chiovari is a Senior Software Engineer specialized in developing enterprise software applications with experience on software integration and messaging. His expertise include helping clients build software using industry best practices, Test Driven Design, Weblogic, Oracle Service Bus , Spring Frameworks, JEE. Performance improvements is something that is really passionate about and considers software development not only his job but also his main hobby. Cristian is a DZone MVB and is not an employee of DZone and has posted 10 posts at DZone. You can read more from them at their website. View Full User Profile

The Memento Pattern

10.20.2012
| 4525 views |
  • submit to reddit

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 Cristian Chiovari, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: