Tuesday, January 13, 2015

Memento Design Pattern

Type : Behavioral Design Pattern


Summary

Memento design pattern is used when we want to save the state of an object so that we can restore later on.

Details

Momento Design Pattern works with three kind of Objects

Originator : Originator is the object that has internal states.
CaretakerCaretaker is the helper class that is responsible for storing and restoring the state of the Originator’s state through Memento object.
Memento : It stores internal state of the Originator, it can be an Inner Class to Originator Class

Advantages

The memento pattern provides a way of recording the internal state of an object in a separate 
object. 

Memento design pattern removes need for multiple creation of the same object for the sole purpose of saving its state. 

The memento simplifies the Originator since the responsibility of managing Memento storage is no longer centralized at the Originator but rather distributed among the Caretakers.

Disadvantages

The Memento object must provide two types of interfaces: a narrow interface to the Caretaker and a wide interface to the Originator. That is, it must acts like a black box to 
everything except for the class that created it. 

Using Mementos might be expensive if the Originator must store a large portion of its state information in the Memento or if the Caretakers constantly request and return the 
Mementos to the Originator. 


Class Diagram


No comments :

Post a Comment