Reputation: 4172
I am not 100% sure of the role of the Presenter vs the Model in the MVP pattern. From what I understand the Presenter holds references to both Models and Views, observes them, and communicates changes in the Model to the View and vice versa.
But is that 'all' the Presenter does? For example, should validation code for user input be in the Presenter?
And then there is the issue of dialogs. Should these have their own Presenter or should they be using the Presenter of their underlying window?
Upvotes: 3
Views: 1494
Reputation: 943
Correct, the presenter holds references to both the view and the model and is responsible for creating them and mediating between them (the extent of which is dependent upon the specific pattern used)
The presenter contains the UI business logic, as an example clicking a save button
The models responsibility in the MVP triad is just there to hold the information for this view. It may be that it is a specialised class just for this purpose or a class from your domain model.
Validation depends on your circumstances. In a simple application the presenter may well be the correct place for it, however this can lead to code duplication. A domain model is the more central location but can mean more plumbing to get it talking to your presenter/view.
Hope that helps
Upvotes: 3