Correct way to trigger object clone/memento when property changes

Posted by Jay on Stack Overflow See other posts from Stack Overflow or by Jay
Published on 2010-03-29T22:26:14Z Indexed on 2010/03/29 22:33 UTC
Read the original article Hit count: 351

Filed under:
|
|
|

Hi,

I have a big doubt about the correct way to save an object state (clone object), if necessary to rollback the changes, when a property has changed. I know that the IEditableObject interface exists for those cases but during some tests the BeginEdit would just fire like crazy (I have a DataGrid whose values can be edited but I won't need to keep the state of the object in these cases).

I'm following the MVP design pattern in my project and the view's DataContext is a wrapper of my presenter.Let's say I have a CheckBox/TextBox in my UI and when that textbox's value changes, the property bound in the wrapper gets set.Currently, before setting the new value i'm raising an event to the presenter (something like PropertyChanging) that clones my wrapper.

I'm doing this because I don't think that job should be done by the wrapper itself but by the presenter.Is this a correct approach?

Raising the event is an acceptable solution? I thought of other possible ideas:

  • Interface between presenter and wrapper;
  • Use explicit binding and trigger the binding after saving object's state;

What is your opinion about the best way to do this? Should I just keep IEditableObject, is this the best way?

Best Regards

© Stack Overflow or respective owner

Related posts about c#

Related posts about propertychanged