How should I implement a UI for IsDirty using the Model-View-Presenter pattern?

The view should never be dirty. Only your model.

The view should never be dirty. Only your model. Then you can simply have an event that triggers when your model becomes dirty and one for when it becomes clean.

1 That was my initial thinking. The model is what would become dirty and the view could reflect that fact. So I would then assume that the model would have to implement a isdirty property.

– David Dec 30 '09 at 21:09.

Well could you make all of your controls have auto postback on changes enabled where they call _presenter.MarkDirty() or some similar method. Or you could allow the save button to be used but if the object is clean to then respond with a no changes made dialog or similar.

Autopost back might not be the most correct word in WinForms but it should convey my point atleast. – Chris Marisic Dec 30 '09 at 22:31.

I agree with @Pace that only the model should be dirty. I just want to add here (as this seems to be about . Net) that you can use CSLA for the implementation of your model, and you get IsDirty funcionality (and a lot of other things) for free.

Update: Is CSLA not about the business layer? Yes indeed, but I think an IsDirty method belongs in the business layer. You speak of implementing an IsDirty on your DTO, but the moment you do that, the object isn't a DTO anymore (as it does more than transferring data).

Also, you could use CSLA as an intermediate layer between your DTO's and your presentation layer, although this would be a little too much overhead if your intention is only to use the IsDirty functionality. The point is: The moment you start putting 'functionality' into your DTO's, I don't see why you wouldn't expose CSLA objects from your business layer in stead of simple DTO's.

The question I've posed is about presentation. My Business objects are not exposed to the presentation layer. – David Dec 31 '09 at 11:25 @fretje I agree that as soon as I put a isDirty property into a DTO then its no longer a DTO.

So on this basis I would assume that doing so is indeed wrong, which is why I asked if it would then be a case of extracting the data from the DTO and pushing it into another object for presentation purposes. My particular implementation does not expose domain objects to the presentation layer as I quite liked this approach although I know there is much debate on this subject. – David Dec 31 '09 at 13:43.

Here is what I do, the view itself can track if the user has attempted to modify the data. When this happens it can notify the presenter that the view data has changed and the presenter can act on this event to enable/disable the save button. This is the simplest solution I have found so far otherwise you have to have change tracking on the DTO/Data object itself.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions