Reading about MVP pattern I found there are two communication patterns between View and Presenter:
View doesn't know Presenter but provides UI controls implementing
HasClickHandler
interface where Presenter registers its event handlers.View knows Presenter, particularly it knows handler method names in Presenter, e.g., when a Submit button is clicked in View, a view calls a
onSubmitButtonClicked()
public method in Presenter.
I found the latter to be easier for JUnit testing, because I can directly simulate submitting event to Presenter. However, my understanding was that the View should not know about the Presenter.
The third approach to resolve the trade-off is to let the Presenter registers event handlers in the View's controls, where the handlers calls public Presenter methods:
public void bind() {
display.getSubmitButton().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
onSubmitButtonClicked();
}
});
}
But this introduces a lot of boilerplate code.
What is the right pattern for View-Presenter communication?