Difference between Observer, Pub/Sub, and Data Binding Ask Question

Difference between Observer, Pub/Sub, and Data Binding Ask Question

What is the difference between the Observer Pattern, Publish/Subscribe, and Data Binding?

I searched around a bit on Stack Overflow and did not find any good answers.

What I have come to believe is that data binding is a generic term and there are different ways of implementing it such as the Observer Pattern or the Pub/Sub pattern. With the Observer pattern, an Observable updates its Observers. With Pub/Sub, 0-many publishers can publish messages of certain classes and 0-many subscribers can subscribe to messages of certain classes.

Are there other patterns of implementing "data binding"?

ベストアンサー1

There are two major differences between Observer/Observable and Publisher/Subscriber patterns:

  1. Observer/Observable pattern is mostly implemented in a synchronous way, i.e. the observable calls the appropriate method of all its observers when some event occurs. The Publisher/Subscriber pattern is mostly implemented in an asynchronous way (using message queue).

  2. In the Observer/Observable pattern, the observers are aware of the observable. Whereas, in Publisher/Subscriber, publishers and subscribers don't need to know each other. They simply communicate with the help of message queues.

As you mentioned correctly, data binding is a generic term and it can be implemented using either Observer/Observable or Publisher/Subscriber method. Data is the Publisher/Observable.

おすすめ記事