MVP:View 是否应该实现 Presenter 的接口,反之亦然? [英] MVP: Should the View implement a Presenter's interface or vice versa?

查看:18
本文介绍了MVP:View 是否应该实现 Presenter 的接口,反之亦然?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GWT 做我的第一步.看完之后有个疑问:

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

在第一个示例中,Presenter 定义了 View 的接口.

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();
  }
}

在第二个中,View 定义了 Presenter 的接口.

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?

我应该选择哪个?

推荐答案

我认为你应该在你的问题中使用定义"这个词而不是实现",如果是这样,那么哪个并不重要类定义接口.

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.

您可以通过在自己的文件中定义接口来做一些不同的事情.归根结底,重要的是 Presenter 实现 Presenter 接口和 View 实现 View 接口.

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.

这篇关于MVP:View 是否应该实现 Presenter 的接口,反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆