Traditional Culture Encyclopedia - Traditional virtues - Difference between Observer Mode and Publish-Subscribe Mode
Difference between Observer Mode and Publish-Subscribe Mode
The observer pattern defines a one-to-many dependency between objects. When the state of an object changes, all the objects that depend on it will be notified and updated automatically. Observer mode belongs to behavior mode, which focuses on the communication between objects. Observer mode is the communication between observer and observed. Observer mode has another name "publish-subscribe mode" or "subscribe-publish mode". Subscribers and subscription targets are linked together. When the subscription target changes, subscribers will be notified one by one.
2 cases
3 Main problems to be solved
When notifying other objects of an object's state change, we should consider ease of use and low coupling to ensure a high degree of cooperation.
Four advantages
Five shortcomings
1 Introduction
In fact, there is no publish-subscribe mode among the 24 basic design patterns. As mentioned above, it is just another name for the observer mode. But after the precipitation of time, it seems that he has become powerful, independent of the observer mode and has become a different design mode. In the current publish-subscribe mode, the message sender called publisher will not send the message directly to the subscriber, that is to say, the publisher and subscriber do not know each other's existence. There is a third component between publisher and subscriber, called message broker or dispatch center or middleware, which maintains the connection between publisher and subscriber, filters all incoming messages from publisher and distributes them to subscribers accordingly.
2 cases
Three advantages
Four shortcomings
5 mainly solve problems
Publish-subscribe pattern is a common front-end design pattern, which is widely used in mainstream MVVM framework. Its main functions are as follows:
The front-end event binding has three elements:
On the surface:
A deeper layer:
From the use level.
- Previous article:A speech on filial piety
- Next article:What is the meaning of chorus
- Related articles
- Internet Style ppt Template ¡ª¡ª How to Make Internet Plus ppt?
- Character traits in the four famous novels
- How to play Hearthstone Legends Tavern Wargames
- A poem about sending letters.
- The college entrance examination time jiangxi 2023 schedule
- What is the development history of ancient leather technology in China?
- Qin, chess, books, paintings, Mei Lan and Zhu Ju, what is eight?
- Why do they leave the lights on all night on New Year's Eve?... The lights stay on all night on New Year's Eve.
- Dandan's role as an actress
- A composition about the spring outing of Tinghu New District Experimental School in Yancheng People¡¯s Park