MVP: Questions about the Host Role

I'm not 100% sure about the role of Presenter and Model in MVP pattern. From what I understand, the Presenter keeps links to Models and Views, notices them and communicates changes in Model to View and vice versa.

But is this "all" that the Leader does? For example, should the validation code for user input be in Presenter?

And then there is a problem with dialog boxes. Should they have their own presenter or should they use their main window's presenter?

+3


source to share


1 answer


That's right, the presenter holds links to both the view and the model and is responsible for creating them and mediating between them (the extent of which depends on the particular template used)

The presenter contains the business logic of the user interface, as an example of pressing the save button

  • ui signals the presenter to say to save.
  • the presenter saves the model.


The responsibility for modeling in the MVP triad is there to store the information for that view. It might be a specialized class just for this purpose, or a class from your domain model.

Validation depends on your circumstances. In a simple application, the presenter might be the right place for it, but it might lead to duplicate code. The domain model is more central, but can mean more plumbing to make it talk to your presenter / view.

Hope it helps

+3


source







All Articles