是否有将guava EventBus放入GUI应用程序的最佳位置? 模型,视图或控制器中是否有? 或三个级别的三个EventBus? 或者只有两个?
谢谢。
Is there a best place to put a guava EventBus in a GUI application ? Is there in the Model, the View, or the Controler ? Or three EventBus in the three levels ? Or only two of them ?
Thanks.
最满意答案
事件总线设计模式通常用于Swing应用程序(如其他SO问题中所述 )。
Guava的EventBus只是设计模式的另一个实现,有一些很简单的技巧来简化事件处理(比如使用注释)。 但使用设计模式的目标保持不变。
如果我是你,我会研究如何在富客户端应用程序(在SO / Google上)中使用事件总线模式,同时使用Guava EventBus来简化代码。
EventBus应该是IMO的单身人士(最好通过Google Guice或其他一些DI框架注入)。
我不是Swing dev,但我已经完成了GWT开发。 不久之前,GWT应用程序的MVP / EventBus架构有了很大的推动力。 它可能是调查它,看看你是否可以将相同的想法应用到你的Swing应用程序。
The event bus design pattern is often used in Swing applications (as mentioned in this other SO question).
Guava's EventBus is just another implementation of the design pattern, with some cool tricks to simplify event handling (such as using annotations). But the goal of using the design pattern stays the same.
If I were you, I'd look into how the event bus pattern is usually used in rich client applications (on SO / Google), while using the Guava EventBus to simplify your code.
The EventBus should IMO be a singleton (ideally injected through Google Guice or some other DI framework).
I'm not a Swing dev, but I've done GWT development. A while ago, there was a big push toward the MVP / EventBus architecture for GWT applications. It might be work looking into it, to see if you could apply the same ideas to your Swing app.
更多推荐
发布评论