I'm using POCOs (class objects) for every type of data when in memory. I have a myraid set of functions that operate on these and modify them in different ways. What is a simple way to achieve undo/redo functionality with minimal changes to the code? Some ideas:
Log changes using ORM - Property-level logging - The methods that modify the POCOs should log every single property they modify, or modify properties via a ORM instead of operating directly on said POCOs. The ORM would log changes and be able to revert when needed.
Deep clone and diff - Memento pattern - Save deep clones of objects before modifying them (wasted memory, slow). After modifications are done, call a function that calculates differences in object properties (must iterate thru all props, slow, tedious, recursive). Differences are stored in a log to be able to revert it later.
Each command supports undo/redo - Command pattern - The classical approach, but it would required too many additions to the code. I'm looking for something generic, and ideally something that doesn't require rewriting the app from the ground up.
I don't know the typical approaches to this kind of problem, but considering its fairly common I'm sure there are good patterns to solving this without much hassle. Do you know of any pattern/library that handles history for POCOs in a simple way?
I'm currently reviewing the following but still looking for better approaches.
- http://www.codeproject.com/Articles/43436/Undo-Redo-Framework
- http://www.codeproject.com/Articles/10947/A-simple-framework-for-adding-undo-redo-support
- http://www.codeproject.com/Articles/456591/Simple-Undo-redo-library-for-Csharp-NET
- http://www.codeproject.com/Articles/1356/Undo-Manager
- http://www.codeproject.com/Articles/10576/An-Undo-Redo-Buffer-Framework
- http://www.codeproject.com/Articles/19550/Automated-Undo-Redo-library-based-on-Csharp-Generi
- http://www.codeproject.com/Articles/33371/Multilevel-Undo-and-Redo-Implementation-in-Csharp-