Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Motivation for Event Bus in GWT

I am creating an MVP-like application in GWT.

  • There are multiple panels, and each one is visible at all times.
  • Each panel has a Presenter, and there is a single AppController which sits above all Presenters.
  • There are some application-level events which arise within one Presenter but have implications for other Presenters.
  • The suggested architecture for this seems to involve an Event Bus. However, I'm not sure I see the advantage over something simpler.
  • In particular, wouldn't it be cleaner to simply allow the AppController (and only the AppController) to subscribe to events from any Presenter? The AppController can then tell each Presenter what to do, given the event.
  • The "Event Bus" seems like a quasi-global variable. But if you can accomplish the same thing with more precisely defined methods (i.e. the methods which AppController calls on each Presenter) isn't that preferable?

To put my concern more precisely: why introduce an Event Bus at all, rather than simply letting events "bubble up" to the appropriate decision-making level? To me this seems like the most straightforward extension of the MVP concept, and it doesn't require the new idea of an Event Bus. I don't understand what problem the Event Bus was introduced to solve.

like image 587
Mike Kayser Avatar asked Feb 12 '13 07:02

Mike Kayser


People also ask

Why do we need event bus?

Eventbuses are useful when you don't want components to depend on each other. Instead of a component having many references to other components, it can just send Events to an Eventbus and does not have to worry about who will take care of them.

What is event bus in GWT?

EventBus dispatches Events to interested parties. It eases decoupling by allowing objects to interact without having direct dependencies upon one another, and without requiring event sources to deal with maintaining handler lists.

What is an event bus?

EventBus is an open-source library for Android and Java using the publisher/subscriber pattern for loose coupling. EventBus enables central communication to decoupled classes with just a few lines of code – simplifying the code, removing dependencies, and speeding up app development.


1 Answers

The advantage of the eventbus is separation of the code.

You can just fire custom events to the bus and don't need to care about your event anymore. Every presenter subscribes only to that events, which it really needs to know. This will lead into cleaner code because, you don't have to create a dispatcher which has to know all presenter to delegate events to them.

In my opinion, the eventbus is a really good thing, to make the code clean and easily understandable.

like image 196
Christian Kuetbach Avatar answered Oct 02 '22 20:10

Christian Kuetbach