Reputation: 5194
In MVP the View offers getter method to the interfaces of the widgets - like hasClickHandler
aso. - so that the presenter can access these ClickHandlers in order to add listeners and set values.
This makes the view really dumb.
If you want to test an mvp presenter you have to mock the view and you have to create mocks for buttons in order to simulate a click on the button.
On the other hand in MVP2 the view knows about the presenter and the presenter offers methods like onButtonClick
and the view add that ui handler. This makes the view aware of the presenter but I think this easier to test.
So what are the pros and cons of MVP and MVP2?
Is it realy possible to write mocks for every widget in order to create good view mocks?
A good thing of MVP respectivly to MVC is, you know what goes into the Presenter, the View and the Model. I am not quite shure if MVP2 makes this as clear as MVP.
What are your experiance?
Upvotes: 1
Views: 306
Reputation: 17489
I used both approaches and I think there are two advantages of using the MVP2 pattern (view calls methods in presenter by a presenter interface):
HasXXXHandler
methods of the view. HasXXXHandler
interfaces and with BDD you only need to test if the presenter's interface function are called. Also MVP is just a pattern and like any other design patterns its just a guideline. It's not necessary to make your life harder just in order to stick to the purest implementation.
Upvotes: 2