Search code examples
javagwtmvpgwt-mvp

MVP: Should the View implement a Presenter's interface or vice versa?


I am doing my first steps with GWT. I have a question after reading:

In the first example the Presenter defines the interface for the View.

public class ContactsPresenter implements Presenter {
  ...
  public interface Display extends HasValue<List<String>> {
    HasClickHandlers getAddButton();
    HasClickHandlers getDeleteButton();
    HasClickHandlers getList();
    void setData(List<String> data);
    int getClickedRow(ClickEvent event);
    List<Integer> getSelectedRows();
    Widget asWidget();
  }
}

And in the second one, the View defines the interface for the Presenter.

public interface ContactsView<T> {

  public interface Presenter<T> {
    void onAddButtonClicked();
    void onDeleteButtonClicked();
    void onItemClicked(T clickedItem);
    void onItemSelected(T selectedItem);
  }

  void setPresenter(Presenter<T> presenter);
  void setColumnDefinitions(List<ColumnDefinition<T>> columnDefinitions);
  void setRowData(List<T> rowData);
  Widget asWidget();
}

What's the idea of this difference?

Which should I choose?


Solution

  • I think you should have used the word 'defines' in your question instead of 'implements' and if thats the case then it does not matter which class defines the interface.

    You could do something different by defining the interfaces in its own files. At the end of the day all that matters is the Presenter implementing the Presenter interface and the View implementing the View interface.