What is the difference between IEditableObject and IRevertibleChangeTracking?
Asked Answered
R

2

26

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?

Rillis answered 3/6, 2010 at 14:41 Comment(0)
R
29

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.

Remembrance answered 3/6, 2010 at 15:4 Comment(4)
+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.Jurat
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.Remembrance
Thank you. BTW, you just got a new reader for your blog. It's really good.Jurat
Attention 2020 Googlers: a rather nice combined effort is mentioned here on Code Review.Bihari
F
1

IEditableObject is used for short term, revertanble modifications such as dialog boxes.

IRevertibleChangeTracking is used for long-term, revertible changes such as editing a record and tracking whether or not the record needs to be saved.

I often implement both interfaces so that I have the ability to support two levels of undo.

Fleury answered 20/2, 2015 at 19:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.