I am working on a system that needs to exhibit these behaviours:
- Audit Trail
- Undo / Revert to a particular version (such an action will itself be audit logged)
I have seen a slightly similar question here, but it deals with only part of what I'm trying to do. Further more, I want to capture the entire life cycle of an object (i.e. CRUD).
The way I intend to implement this is as follows:
- Have a ChangeManager class based on the observer pattern
- Derive my objects from a base object that "wraps up" changes in a command pattern
- Notify the ChangeManager with the command object on any of the CRUD events
Note: A 'change' Command will consist of:
- an (ordered) collection of 2-tuples detailing the field change (prev, new)
- id of user that made the change
- timestamp of the change
This is just "off of the top of my head" - and there may be holes in the approach I am thinking of taking - I would appreciate some help from people who have implemented this sort of behaviour before, and also general advise, pros and cons on the approach I have outlined above - or maybe a better/alternative approach. A snippet or two to point me in the right direction will also be greatly appreciated!.
I will be using C# as the implementation language.