The only way to get any closer to a perfect MVP passive view pattern would be to write your own MVP triads for the dialogs instead of using the WinForms dialogs. Then you could move the dialog creation logic from the view to the presenter.
This gets into the topic of communication between mvp triads, a topic which is usually glossed over when examining this pattern. What I've found works for me is to connect triads at their presenters.
public class PersistenceStatePresenter
{
...
public Save
{
string sFilename;
if (_model.Filename == _model.DefaultName || _model.Filename == null)
{
var openDialogPresenter = new OpenDialogPresenter();
openDialogPresenter.Show();
if(!openDialogPresenter.Cancel)
{
return; // user canceled the save request.
}
else
sFilename = openDialogPresenter.FileName;
...
The Show()
method, of course, is responsible for showing an unmentioned OpenDialogView
, which would accept the users input and pass it along to the OpenDialogPresenter
. In any case, it should be starting to become clear that a presenter is an elaborate middleman. Under different circumstances, you might be tempted to refactor a middleman out but here its is intentional to:
- Keep logic out of the view, where it is harder to test
- Avoid direct dependencies between the view and the model
At times I've also seen the model used for MVP triad communication. The benefit of this is the presenter's don't need to know each other exist. Its usually accomplished by setting a state in the model, which triggers an event, which another presenter then listens for. An interesting idea. One I've not used personally.
Here's a few links with some of the techniques others have used to deal with triad communication:
- http://www.rickardnilsson.net/post/The-Humble-dialog-v2.aspx
- http://spin.atomicobject.com/2008/01/30/presenter-first-get-your-triads-talking/