vendredi 3 juillet 2015

EventBus android implementation, why reflection

I am using EventBus in my projects, it works well, but some colleges said that they had problems with this library. I am not talking about concreate implementation of EventBus pattern , there are two widely used implementations.
But both of them use reflection. Reflection is not cheap especially on mobile devices.
So my question is why not to avoid using reflection ??
My idea is, for example, use Android Service as event bus manager, or you can use custom application class that is available during application life. For instance service will be able to register subscribers, notify them, unregister ... everything that can EventBus do. As far as service is high priority component, we can be sure that it will be alive when we need to send event, futhermore if we will have reference to it in application class, for example.
About subscribers, why not to just implement generic interface OnEventSubscriber<E extends BaseEvent>, if you are interested in multiple events you can implement another interface with appropriate event type. And implement onEvent method with specific type.

Why current implementation is using reflection approach instead of something described above ? People who have created these libraries are highly experienced developers, so there have to be reasons why implementation is as it is.
I will be grateful for any explanations, comments. Thx in advance.





Aucun commentaire:

Enregistrer un commentaire