I've used approach #1 before (call a method on the view, it creates a
dialog) with good success. As long as it isn't complicated, that
works just fine, and I can't imagine it would be something significant
enough to require testing.
More recently, however, I've taken to Approach #3, whereby you have a
whole separate view/presenter for the dialog boxes. I go one extra
step and hide this behind a simple interface. I think this would work
a bit better for your implementation of the MVP pattern.
Snippet from inside one of my page presenters:
ChooseOneDialog<Suggestion> dialog =
this.bundle.getApplicationFactory().createChooseOneDialog();
dialog.addSelectionHandler(this.selectionHandler);
dialog.setOptions(ContactSuggestion.translate(result));
dialog.show();
The application factory is part of the resource bundle made available
to all of my presenters. The ChooseOneDialog interface hides the
implementation, but inside it is a fairly standard presenter/view.
The methods on the ChooseOneDialog interface simply delegate to the
presenter.
This allows me to keep this code separate and reusable, while at the
same time allowing me to mock it out for testing purposes, since both
the ApplicationFactory and the ChooseOneDialog are only known through
their interfaces. The bundle itself is actually a concrete class, but
all it does is contain interfaces, so it doesn't need mocking up.
-Ben
On Apr 7, 7:14 am, Terry Bachard <
terram...@gmail.com> wrote:
> Thanks Jen.
>
> Yes, I can see how that works. Unfortunately I haven't implemented my MVP
> pattern this way so far, the view cannot delegate to the presenter; only the
> presenter can talk to the view...
>
> Cheers,
> Cormac
>