4 ms·
Instead of posting a string and a payload to the event bus, which a listener picks up and unpacks to call method in the receiver, just call the method. It does
by wffurr 5y ago
Instead of posting a string and a payload to the event bus, which a listener picks up and unpacks to call method in the receiver, just call the method.
It does introduce a direct dependency where it was indirect before, but is otherwise much simpler and significantly faster than all the string comparisons.
- void_mint 5y ago> It does introduce a direct dependency where it was indirect before Which is okay if you've used any amount of DI and testability-focused thinking to set up your code. The event bus pattern works great if you don't know (or want to know) what's going to happen to an event once it's emitted. If the only thing that happens is a different method in your app gets triggered, you should really just trigger that method and skip the event bus altogether.
- ncann 5y agoAh ok I guess my confusion is from the fact that there's no explicit "string" being passed around with this library, but the concept of a payload makes sense.
- hota_mazi 5y agoIntroducing the direct dependency is exactly what you want to avoid and what event buses provide. With your approach, you are coupling views and model with n*m links, with an event bus, it's just n+m. Much easier to decouple your logic. I do agree with you that I'm not a fan of the loss of static typing that event buses usually introduce.
- an_opabinia 5y ago> Introducing the direct dependency is exactly what you want to avoid Why? It's a GUI application on Android. Everything that listens to this event bus is a direct dependency configured at build time. Every modern optimization, like ahead of time compilation and code stripping, benefits from direct dependencies. This is why I used the word toxic, and not stupid.
- the_gipsy 5y agoCalling by strings is not decoupling. You just fooled the type system. Or yourself, if you want.
- chris_overseas 5y agoThere is no string comparison here, the subscriptions and posting of events is based on the class of the POJO being sent.