I am creating an MVP-like application in GWT.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With