I've been working on a WPF application that involves moving many shapes. It is mostly MVVM and relies heavily on commands. I had not worried about Undo/Redo until just recently. I don't think it will be too difficult since most of my changes involve commands that inherit a base class CommandBase that implements ICommand.
So far I have added another Interface named IUndoCommand that uses ICommand. I have added an Undo method that will perform the operations needed when an undo is called.
I will be using a stack for both Undo and Redo, but I'm running in to an issue with the parameters for the Execute/Undo methods. Is there a proper way to store these parameters of type object? Is it advisable to add a field/method to IUndoCommand? If so should I set it in the Execute method or in a constructor (if I even can.)
If not should I pass it as it's own object in the Stack?
Secondly, (although this can probably be it's own question) is there a better data structure to track multiple commands? I currently have a loop that runs multiple commands to move multiple selected shapes and would like to allow one undo to undo them all. I guess I could convert this to a command on it's own and pass commands to it, but again I'm new to this and would rather do it right.
Thanks for reading and any help would be greatly appreciated.
Sources: