Implementing undo and redo functionality
Nearly every application has some way to undo one operation or more, and many applications also allow a redo of reverted steps. Accidents can happen in both ways; undoing an unwanted undo can save a lot of time and stress for the user.
What do we need to create undo and redo?
To be able to undo a simple operation that changes object properties, we need to save the previous values. Undoing that change could then be done by applying the “old” values to the same object, and restoring the state of that object before the change.
For more complex undo operations, storing the operation type is also required. If we delete something, the undo step must recreate the object with the same properties, and vice versa – undoing the creation of a new object will delete that object.
Other options could be also taken into account. Do we want to store the absolute previous values or just the difference to the new values? By...