June 16th, 2010, 07:43 AM
Mvp design pattern - question
When I have a button which only changes something in my view (e.g. such that some text appears if I press it), can I write its whole code in the file with my view or should I include event handling of this button in the presenter? This is problem for me, because I don't know, if the presenter handles all events from the view or only these, which change something in the model?
Thanks in advance
June 16th, 2010, 10:15 AM
I would say there is no need to put the handling code in the presenter, if it's not required there. The Presenter should subscribe to the View events, but if the event is not related to the model or the application logic, and it's purely related to the the view, then why to handle the event inside the Presenter?
Another reason to put it in presenter could be to test it. Let's say by replacing the Presenter with a Mock presenter you can test the View.
June 16th, 2010, 05:33 PM
The View should contain the event handler that is registered for the UI operations (e.g. on button click). However, the handler should be a dumb callback that delegates the work to the Presenter. This allows the Presenter to be tested seperate from the view (normal unit test) because it has no direct UI coupling. The View is lightweight and dumb, so the heavy-weight integration tests can be kept slim since there is little extra needing to be validated.
This is a common idiom in MVP for web applications, and the Google I/O Gwt testing talk has a lot of good suggestions that translate across frameworks.
Core design principles
when developing software systems.
See my open-source project
as an example of professional code.
The opinions expressed do not represent those of my employer.