15

我正在做我的第一步GWT。阅读后我有一个问题:

在第一个示例中,Presenter定义了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.

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

这种差异的想法是什么?

我应该选择哪个?

4

3 回答 3

2

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

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

于 2010-07-22T13:02:59.867 回答
2

@deepak these are valid concerns . Word is infect implementation not definition .

Let me explain . In first example presenters hold the contract to what view must implement in other words drives what should be implemented by views a classical MVP approach .

Things get confusing in second example. Where Presenter has no control over what view must implement . This is not MVP and google is calling it as MVP . There is no way you can test the views with JRE /unit tests using this approach . That does not make it bad though just not MVP and google should not call this MVP or they must explain as to why is it an MVP ?

@Saket Bansal separating out interface is not correct approach . It will result in hard to maintain code as application grows .

In my opinion you can take either approach , I remember google saying some where first one worked for them for adwords and second for wave .

Any how you should also look at framworks like GWTP or ERRAI from jboss

于 2010-09-14T00:23:48.240 回答
0

在第二个教程中,代码更改为使用 Presenter 接口(在视图中定义)以适应使用 UiBinders 和 Java 泛型。我认为 Presenter 界面已移至 View 界面,因为它们都共享相同的通用 T。

于 2010-07-22T18:35:17.457 回答