Reputation: 11
I'm developing a C# application that has the following two requirements:
Are there any best practices for doing this? I have read that implementing the command pattern is useful for the undo/redo requirement. The problem for me comes in persisting the changes to the database. I am using business entities and not DataSets, and I cannot use Linq to SQL or Entity Framework, so I am not sure how to track changes made to these entities to persist to the database when the user clicks save.
My question is:
Is it advisable to implement the Unit of Work pattern to track changes or is there a better way? I am not sure how that will combine with the command pattern, e.g. is the unit of work passed to the command which marks an entity as dirty/new/deleted, and what happens when the undo method of a command is executed? Is the entity marked as dirty/new/deleted again or can it be removed from the unit of work somehow?
Upvotes: 1
Views: 1597
Reputation: 101192
Use the Command Pattern with the following change (in the regular command pattern you have an invoke method. In this specialization you use a dispatcher to invoke the command).
Create a Dispatcher class which all commands are invoked through. Create an event in that class which is invoked for all commands. Create a class which listens on that event. Let that class save serialize all changes to your database.
Upvotes: 0
Reputation: 1534
http://en.wikipedia.org/wiki/Memento_pattern
Command will change your business entities, they will store current state in state objects, and list of previous state entries, save will save current state, rollback will restore previous state.
Upvotes: 2