开发者

GWT Tutorial's code with an interface contained in a class

I have been playing around with GTK since a couple of days now,while going through sample code and tutorial I stumbled across this c开发者_如何学Code in the sample project download.

package com.google.gwt.sample.contacts.client.presenter;

import com.google.gwt.sample.contacts.client.ContactsServiceAsync;
import com.google.gwt.sample.contacts.client.event.AddContactEvent;
import com.google.gwt.sample.contacts.client.event.EditContactEvent;
import com.google.gwt.sample.contacts.shared.ContactDetails;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;

import java.util.ArrayList;
import java.util.List;

public class ContactsPresenter implements Presenter {  

  private List<ContactDetails> contactDetails;

  public interface Display {
    HasClickHandlers getAddButton();
    HasClickHandlers getDeleteButton();
    HasClickHandlers getList();
    void setData(List<String> data);
    int getClickedRow(ClickEvent event);
    List<Integer> getSelectedRows();
    Widget asWidget();
  } 

..............

An interface Display is created inside class ContactsPresent.

On the turorial a code snippet

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

The tutorial can be found here

What does the code supposed to be doing when we declare an Interface inside a Class? Can anyone explain?


This is a public nested interface (as opposed to private or package-private) and behaves the same way as top-level interface. The only difference is that you refer to it via ContainingClass.NestedInterface syntax. The rest is the same.

In the particular case of GWT MVP, this nested interface is used by Presenter to access the View, where View implements Presenter.Display. One of the goals of GWT MVP is to have testable Presenters (where business logic is) which means that you have to be able to replace View (which is a GUI element and is implementation dependent) with a mock View. To achieve this an intermediary interface is defined for the Presenter to access the View.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜