Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Presenter Perform GUI Logic in the MVP Pattern?

Tags:

c#

mvp

winforms

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?

like image 889
Martijn Avatar asked Feb 06 '12 15:02

Martijn


2 Answers

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.

like image 127
Larry Gasik Avatar answered Oct 19 '22 23:10

Larry Gasik


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.

like image 20
Igby Largeman Avatar answered Oct 19 '22 22:10

Igby Largeman