4 ms·
> Coupling between callers and responders is removed. This makes life much easier when we want to refactor our code, since objects don’t directly reference one
by V-2 9y ago
> Coupling between callers and responders is removed. This makes life much easier when we want to refactor our code, since objects don’t directly reference one another.
This is listed under advantages, but I'd say it's a mixed blessing at best.
Objects no longer directly referencing eachother means it is now way harder to reason about and analyze the dependencies in your codebase.
The dependency graph no longer exists in design time like it did before, lending itself to various static code analysis tools that could even draw you a pretty diagram thereof. Now it's grown and shaped in run-time.
Event buses are sort of like a "goto". It's sure convenient to be just sending events back and forth through some static event bus, but once things go south, trying to trace the root cause will turn you into Carrie Mathison.
In Android world, event buses are considered legacy now. One of the most popular choices, Otto, is explicitly deprecated (in favour of RxJava that the authors recommend to use instead).
- krzat 9y agoThe most fun is when one message causes another message to be sent. And then some components start depending on their order, creating implicit state machine of madness.
- V-2 9y agoOh yes, and sticky events, and flipping the "is it handled already?" flag on an event because some subscribers must have exclusivity...