1

I'm unable to distinguish what to use. It seems are all working in a same way but different way but the base logic are same, kindly let me know what is the main difference in all?

Muhammad Waqas
  • 420
  • 4
  • 19
  • 1
    The observer pattern allows us accomplish something extraordinary in software architecture. What that allows us to accomplish is low coupling, high cohesion. What that means is, we are able to avoid connecting all of our class instances together via references in code, but maintain a system of these objects that communicate via an event bus system. In other words,instead of passing references of objects back and forth to allow us to make a callback on a parent activity,for example, we can use EventBus instead.You’ll begin to understand this better when we go through the code in Android Studio. – Hasindu Gajanayake Feb 26 '18 at 08:55

1 Answers1

2

EventBus is just some kind of tool that has been written with Observer-like situations in mind. The general usage of EventBus is to fire events so we can use of the word Observer to fit for it. Observer pattern uses events or messages to notify of a change to objects of interest about the object being observed(changed).

And EventBus is also not observer pattern because if you have N objects and you want to communicate between all of them you need N*N observers if you use the observer pattern but only one global EventBus is enough to do the same job.

So EventBus is the EventBus-pattern.


And LiveData is also considered as an observable data holder class that used in Observer pattern. Unlike a regular observable, LiveDatais lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services.

So LiveData is the Observer pattern for Android, or can be considered the separate LiveData-pattern.

nhoxbypass
  • 9,695
  • 11
  • 48
  • 71