Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any advantages to switch to Otto from Broadcast events

I stumbled upon Otto, and it looks like it's used as a replacement for Broadcast events. I read the doc but, I don't understand if there are much advantages to use Otto.

like image 236
Jesno Gianoli Avatar asked Jan 06 '14 16:01

Jesno Gianoli


People also ask

What are the advantages of event-driven architecture?

Benefits of event-driven architecture. Event-driven architecture can help solve the problems of the close coordination of microservices, error handling and retries, and coordination between development teams.

When should you use event-driven architecture?

Should you use an event-driven architecture? Event-driven architectures are ideal for improving agility and moving quickly. They're commonly found in modern applications that use microservices, or any application that has decoupled components.

How does EventBus work on Android?

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.


2 Answers

Otto should rather be compared to LocalBroadcastManager. This is because the both Otto and LocalBroadcastManager do not support inter-process communication.

Otto's pros:

  • Much less code and more readable code.
  • Complex objects can be passed through (no object serialization is required).
  • Instant value callback via @Producers.

Otto's cons:

  • Otto uses reflection, that is why it might be slower than LocalBroadcastManager if you, for instance, send integer values very frequently.
like image 160
sergej shafarenka Avatar answered Oct 03 '22 17:10

sergej shafarenka


It may not matter depending on the structure of your app, but Otto also doesn't require having a Context handy to send events or register listeners.

like image 24
Argyle Avatar answered Oct 03 '22 16:10

Argyle