4

In the examples provided by Google Web toolkit that they are adding the event handlers in one class only for the whole application.

As in - for Module1, 2 and 3 all events are registered in the main AppController class. I find this a bit monolithic and would not it better when we are using the MVP pattern that we declare a method called bind() in each of the Presenters that is as follows:

public class MyTestPresenter implements Presenter{

     private void bind()
     {
            TestEvent.eventBus.addHandler(TestEvent.Type, new TestEventHandlerImpl() )
     }

}


public class TestEvent
{
 public static SimpleEventBus eventBus = new SimpleEventBus()
}

Query is:

  1. If our application is huge - we would be using one eventbus to populate more than a thousand events in it - or would we design in such a way that we have separate instances of event bus for each module?.

  2. Any cost of keeping the static event bus field. Any better design to give it's instance to all classes - passing it around to all classes through a constructor with each presenter class having it's reference seems a bit of clutter ...

  3. What are activity and places in GWT when it comes to event handling? - Can someone give a pointer to how to understand the concept of activity/place in general?

4

1 回答 1

1

实际上我也不喜欢 GWT 中的事件总线实现。我之前问过smt。现在我开发了一些桌面应用程序,并以另一种方式设计 eventBus。

public interface EventBus {
    void fireEvent(Event event);

    <T extends Event> void addHandler(Class<T> eventType, Handler<T> handler);

    interface Event {
    }

    interface Handler<E extends Event> {
        void handle(E event);
    }
}

所以在通常的 Java 应用程序中我会以其他方式设计它,但在这里我们应该处理与 javascript 等有关的问题。

如果我们的应用程序很大——我们将使用一个事件总线来填充其中的一千多个事件——或者我们是否会设计为每个模块都有单独的事件总线实例?

我也在思考这个问题。我发现没有任何真正的优势。对于模块化,您可以分离事件的可见性。并且有一些缺点。假设您应该在同一个类中处理多个 eventBusse - 代码会很混乱。除此之外,您应该以某种方式将此实例映射到类。

保留静态事件总线字段的任何成本。将实例提供给所有类的任何更好的设计 - 通过构造函数将其传递给所有类,每个演示者类都有它的引用似乎有点混乱......

你可以两者都做。在新的 Activity-Place 框架中,它作为参数传递。

在事件处理方面,GWT 中的活动和位置是什么?- 有人可以指点如何理解活动/地点的一般概念吗?

Activity 它就像您的旧演示者,但没有低级别的视图绑定。就像用于指定窗口的历史条目一样放置。

于 2011-05-11T20:30:17.090 回答