Injecting an EventBus allows you to pass the one instance you want
(SimpleEventBus, ResettableEventBus, CountingEventBus, RecordingEventBus,
or your own subtype), and change that between dev, production, and tests.
--
You received this message because you are subscribed to the Google Groups
Maybe I've misguided you mentioning the SimpleEventBus implementation of
the EventBus interface. The actual question was whether I should use a
*static* EventBus that can be defined in a Common class and reference
this static EventBus from any other view.
E.g. using
*MyView() {*
*// MyView
I had understood, so that doesn't change my answer.
With the static instance, everyone shares exactly the same. With an
injected instance, you can wrap your global singleton eventbus within a
ResettableEventBus in some cases (depending on how you manage your classes
lifecycle), or some other
As GIN also supports static injection it seems like there is not much of a
difference, but:
1.) Using the static way you somehow hide the fact that a class depends on
an event bus
2.) Sometimes its nice to have multiple instances of an event bus.
Especially having multiple ResettableEventBus's
Sorry if I didn't make it clear enough: With the static instance, everyone
shares exactly the same [instance], which means that you cannot choose,
for a particular object, to use a different instance (e.g.
ResettableEventBus), unless you make that object depend explicitly on the
other instance
Not that it's really what you asked (I agree with the replies you've
received), but if you're using the idiom shown in some of the Google
presentations/samples/vids, instead of direct references to the EventBus
instance (which is a class and not an interface ... I don't know why), you
may have
EventBus is a really nice mechanism to *decouple methods from callbacks* by
adding corresponding event handlers to an EventBus.
By nature EventBus is something that should be known to both classes, the
calling and the called class. So you can
*1. pass an EventBus in a constructor or*
*2. use a