Design patterns to facilitate these behaviours (audit trail behaviour and undo)

Viewed 5064

I am working on a system that needs to exhibit these behaviours:

  1. Audit Trail
  2. 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:

  1. Have a ChangeManager class based on the observer pattern
  2. Derive my objects from a base object that "wraps up" changes in a command pattern
  3. 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.

1 Answers
Related