Philosophy behind the memento pattern
Posted
by
TheSilverBullet
on Programmers
See other posts from Programmers
or by TheSilverBullet
Published on 2012-08-27T13:30:04Z
Indexed on
2012/08/28
3:51 UTC
Read the original article
Hit count: 292
design-patterns
I have been reading up on memento pattern from various sources of the internet. Differing information from different sources has left me in confusion regarding why this pattern is actually needed.
The dofactory implementation says that the primary intention of this pattern is to restore the state of the system.
Wiki says that the primary intention is to be able to restore the changes on the system. This gives a different impact - saying that it is possible for a system to have memento implementation with no need to restore. And that ability of restore is a feature of this.
OODesign says that
It is sometimes necessary to capture the internal state of an object at some point and have the ability to restore the object to that state later in time. Such a case is useful in case of error or failure.
So, my question is why exactly do we use this one? Is it to save previous states - or to promote encapsulation between the Caretaker and the Memento? Why is this type of encapsulation so important?
Edit: For those visiting, check out this Implementation!
© Programmers or respective owner