Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Undo, Memento for Composite Object

 
marten kay
Ranch Hand
Posts: 178
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a mutatable class similar to below, note code abridged to illustrate key points. The key point being that the Element and Variable objects in the maps are mutated outside of the Rendition object (via a web html inteface). That is, the composed state of the Rendition object is not handled by methods in the Rendition object.

I now want to implement an undo facility where any changes to the composed state can be reverted through a call to the Rendition.

To achieve this, I understand that I need to do a major refactor to ensure that all changes of state to the composed Rendition object are handled by Rendition which can then generate a memento object for each change.

Before I undertake this refactor, is anybody able to give me further pointers on moving forward?

Thanks

Marten

 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may use "Observer" pattern to cascade your changes.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also look at the Command pattern. This pattern is very suitable for implementing undo-functionality.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic