Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Large scale application development and MVP
  • Large scale application development and MVP - Part II

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?

like image 892
Macarse Avatar asked Jul 22 '10 12:07

Macarse


People also ask

What is MVP architecture paradigm?

Overview. MVP is a user interface architectural pattern engineered to facilitate automated unit testing and improve the separation of concerns in presentation logic: The model is an interface defining the data to be displayed or otherwise acted upon in the user interface.

Why we use MVP architecture?

The reason why MVP is widely accepted is that it provides modularity, testability, and a more clean and maintainable codebase. It is composed of the following three components: Model: Layer for storing data.


1 Answers

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.

like image 193
prav Avatar answered Sep 22 '22 21:09

prav