views:

192

answers:

2

Please explain the responsibilities of the presenter and of the business logic, and their interaction in MVP passive view. Can the business logic(is it the same as model?) modify the view? Or will it pollute the MVP passive view design? How exactly should presenter use the underlying services?

A: 

If you have business logic in the view, how would you test it? That is one thing you should always ask yourself first. So any business logic should be handled in a Presenter or Service that presenter uses. You can send Dto to the view, with additional flags that would tell view how to modify itself. But setting these flags should be done outside of the view.

epitka
Well, there is no business logic in the view. They are separate.MVP says that only the presenter gets to modify the view through an interface. And presenter uses other classes to get things done. So, is it ok for these underlying classes to modify view or not?Right now, I'm leaning towards a solution in which these classes can raise an event and tell the presenter that something on the view needs to be changed, and the presenter can modify the view directly. What I'm trying to avoid is direct data binding between Model and View.
Abhijeet Kashnia
Which underlying classes? Nothing other then the Presenter should be modifying your view. In the consturctor of the presenter you pass it concrete imlpementation of the view interface which presenter and only presenter can then modify.
epitka
Ok, so your answer is no. Only presenter modifies the view.How can I mark your previous comment as the answer?By underlying classes, I mean model and business logic.The presenter is only a coordinator that makes model classes do the actual work. If presenter needs to show the data maintained by model to the view, then what are the options? Data binding (supervising controller? Less testable ?) or pass an instance of view to the model ( not a good option) or raise an event which is accepted by the presenter. Allowing the presenter to query the model for data directly doesn't sound good.
Abhijeet Kashnia
Let's say you have "Name" property in your view interface. You expose property Name on your concrete implementation, and then in the setter of the property you would do something like "ctlTextBox.Text = value;". If it is a complex control, you bind it in there. Your presenter would then do something like "_view.Name = somevalue". If you need I can send you some sample code. To mark answer accepted just click on the check mark next to the answer.
epitka
A: 

I wrote an article that seems to describe exactly what you are referring to. http://coding.infoconex.com/post/(MVP)-Model-View-Presenter-Passive-View.aspx

Jim Scott