Difference between Observer, Pub/Sub, and Data Binding

后端 未结 4 1490
感情败类
感情败类 2020-12-07 06:39

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

I searched around a bit

4条回答
  •  广开言路
    2020-12-07 07:02

    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/Subscriber.

提交回复
热议问题