Memento Pattern
Architecture, Flex April 11th, 2009Yesterday I tried to implement Undo functionality with Command Patterns. The Memento pattern can also be used to do this. So what is the difference between the two?
Well, with Memento pattern the state of an object (the originator) is being stored by a Caretaker class. So if it’s possible to Undo with returning back to a previous state, use Memento pattern. Sometimes however, the originator is too complex to save each time its state (it could be a composite for instance). In that case the undo facility can use commands. Whenever an action is received a compensating action is set up and stored in the undo facility.
Example in Flex of Memento Pattern. I haven’t added too much comments because the code and example should speak for itself.
thx, Lieven Cardoen
Related: Command Pattern Undo Functionality
October 17th, 2009 at 12:24 pm
[...] Related: Memento Pattern [...]