We are working with the MVP pattern, and I was wondering how to deal with GUI actions.
For instance, when the user wants to delete a row from a grid, the user presses the delete button. At this point you can do two things:
1) Call _presenter.DeleteRow()
and the presenter then calls _view.SelectedRow
. Then the presenter calls view.AskUserForConfirmation()
, and when it gets back DialogResult.OK
, the presenter actually deletes the underlying object and refreshes the grid.
2) The form asks the user for confirmation and when the DialogResult
is OK
, then presenter.Delete(myObject)
is called OR presenter.Delete()
is called and within the Delete
method the object is retrieved by calling _view.SelectedRow
.
How do you handle these kinds of situations?
The MVP Pattern is supposed to separate your logic, view, and data access. So when trying to decide where something should go, ask yourself if there is actual business logic in what you're trying to do.
Would you want your business layer to have logic about displaying a pop up window? Probably not. It is just a confirmation message. You may want to have a helper class that generates your stylized pop up window, but that is seperate from your Presenter layer.
Option 2. Asking for confirmation is a UI responsibility that the presenter shouldn't need to worry about. I don't involve the presenter until it's time to actually do something to the model, or until some complex business logic needs to be invoked.
This doesn't mean option 1 is invalid. It just creates unnecessary view/presenter chatter, in my opinion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With