MVP:View应该实现Presenter的界面吗?反之亦然? [英] MVP: Should the View implement a Presenter's interface or vice versa?
问题描述
我正在使用 GWT
来完成我的第一步。
阅读后有一个问题:
在第一个例子中, Presenter
定义了 View
的接口。
public class ContactsPresenter实现Presenter {
...
public interface Display extends HasValue< List< String>> {
HasClickHandlers getAddButton();
HasClickHandlers getDeleteButton();
HasClickHandlers getList();
void setData(List< String> data);
int getClickedRow(ClickEvent event);
列表<整数> getSelectedRows();
Widget asWidget();
$ / code>
在第二个中, 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>演示者);
void setColumnDefinitions(List< ColumnDefinition< T> columnDefinitions);
void setRowData(List< T> rowData);
Widget asWidget();
}
这种差异的主意是什么?
我应该选择哪一个?
我想你应该在你的问题中使用'而不是'实现',如果是这种情况,那么,哪个类定义接口并不重要。
你可以通过定义一些不同的东西在它自己的文件中的接口。在一天结束时,所有重要的事情就是Presenter实现Presenter接口和实现View接口的View。
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?
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.
这篇关于MVP:View应该实现Presenter的界面吗?反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!