0

I'm adding a GUI to an existing command line app. The properties used by the app are held in class(es) and I'm creating a dialog that binds to those options objects. However, if I want to cancel out of that dialog I then have reset the values of my options objects, which is where I'm running into probs.

I could take an internal copy of the option objects and use that to re-populate the original object to allow the cancel/rollback but that seems cumbersome.

I can (somehow) implement an undo function on each class - is there a pattern for that?

I use the GUI controls standalone to hold values and only update the options objects when the dialog has been confirmed.

What's best practise?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
MrTelly
  • 14,657
  • 1
  • 48
  • 81

1 Answers1

1

You should consider creating a new class to be used just by the GUI. GUIs have their own needs.

Make sure to take care of multi thread issues if you have more than one thread accessing the options object.

The design patterns that address undo functionality are called Command and Memento. I think Memento would fit better on this case.

Take a look on this question on SO: Design Pattern for Undo Engine.

The following links are of interest (and many more): http://www.coderanch.com/t/100676/patterns/Memento-Vs-Command-pattern http://www.developer.com/design/article.php/3720566/Working-With-Design-Patterns-Memento.htm http://www.colourcoding.net/blog/archive/2009/07/23/reversibility-patterns-memento-and-command.aspx
Community
  • 1
  • 1
Klinger
  • 4,900
  • 1
  • 30
  • 35