views:

183

answers:

1

What is the difference between IEditableObject and IRevertibleChangeTracking (both from the System.ComponentModel namespace)? It looks as if the first supports explicit transaction whilst the second is more implicit - but the net result is the same. How should I go about implementing this in code? At the moment I do nothing in BeginEdit and call RejectChanges and AcceptChanges in EndEdit and CancelEdit respectively. My problem is that this will also accept the changes made prior to the BeginEdit.

Is that really what Microsoft wanted or am I trying to implement two mutually exclusive interfaces?

+8  A: 

The two interfaces are not mutually exclusive. They are simply intended to support different yet somewhat related scenarios, which might as well be implemented by the same given class. Here's a quick explanation:

IEditableObject Interface

The IEditableObject interface is designed to support the scenario where an object needs to manage its internal state in some particular way while it is being edited.

For that reason the interface includes methods that explicitly mark when the editing phase is started, completed or aborted, so that the appropriate actions can be taken to modify the object's state at those stages.


IRevertibleChangeTracking interface

The IRevertibleChangeTracking interface is designed to support the scenario where an object needs to be able to rollback to its previous state.

The interface has methods that mark when the object's current state should be made permanent or it should be reverted to the last known permanent state.

Enrico Campidoglio
+1: Are you aware of any details about any known implementations of these interfaces or any suggested ways to use them? The MSDN is woefully incomplete here and google doesn't return much more.
SnOrfus
Some of the core classes in ADO.NET are interesting examples. The System.Data.DataRow class exposes both the AcceptChanges/RejectChanges and BeginEdit/CancelEdit/EndEdit methods (although without implementing any of the above interfaces). The BeginEdit method puts a row in state where events and validation are suspended, until either CancelEdit or EndEdit are called. In addition to that CancelEdit also calls RejectChanges, which undos all modifications by reverting the row to its previous values. EndEdit calls AcceptChanges instead, which overwrites the previous values with the current ones.
Enrico Campidoglio
@Enrico Campidoglio: Thank you. BTW, you just got a new reader for your blog. It's really good.
SnOrfus
@SnOrfus Thanks, I appreciate it :-)
Enrico Campidoglio