Is it a bad design to have a global event bus in your application?
How to make sure you don’t end up with a tightly coupled set of components talking to each other all over the application?
Can you think of a mechanism/tools/library in Java world to enforce some discipline on it?
Is it a bad design to have a global event bus in your application?
Share
The problem with a global event bus i.e. an event bus which is accessible to every component (class or object) in your application, is that you have no control who will use the event bus.
If you are the sole developer or are working with a close knit team, it is possible to agree on the conditions when a component can use the event bus. Otherwise all bars are off.
Having said that, there should be a possibility to communicate with the event bus otherwise having it is pointless. By introducing an proxy for the eventbus who is responsible for the actual firing of the event, you can control who depends on the proxy.
By using dependency injection (via a framework like guice or hand-rolled) you can automatically provide the proxy state making the dependency on the eventbus explicit.