Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the implementation effects of the web Observer pattern?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

What are the knowledge points of this article "what are the effects of web Observer Mode?" most people do not understand, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "web Observer Mode implementation effect" article.

Effect.

Implement notifications for non-specific types of objects

Generally speaking, notification is also a kind of call, that is, when the target notifies the observer, the usual practice requires the target class to know about the observer class. The observer pattern defines the observer abstract interface, as long as the specific observer implements the observer interface, it can join the observer queue and receive notifications from the target. In other words, the target class as the notifier does not need to know the details of the concrete observer class in order to achieve decoupling.

Implement notifications for unspecified majority objects

The observer object is logged into the observer list of the target class, and the notification method of the target class simply calls the notification interface of the observer object in the list in turn. Regardless of whether there are more or fewer observer objects in this list, the notification method is exactly the same. The Observer pattern implements notification to an unspecified majority of observers in this way.

Realize

Pull model or push model

The so-called pull model means that the target object only notifies the observer that there is a change, while the details are obtained by the observer himself, while the push model sends the changed content with the notification as much as possible. The expansion of the pull model is flexible, but the efficiency is low, while the efficiency of the push model is high, but the flexibility is insufficient. The two methods have their own advantages and disadvantages and need to be chosen according to the actual situation. As a compromise, it is often a good enough choice to bring both the changed object and the changed type at the same time.

Avoid invalid references

The prerequisite for an observer in observer mode to receive a notification is to log in in the target object. When the observer no longer needs to receive notification from the target object, it needs to cancel the login in time. There are generally no serious problems at this point. A common problem for beginners is that the cancellation of login may be omitted when the observer object is destroyed, resulting in accessing the invalid object on notification. Another situation is that when the observer maintains a reference to the target object, it is also possible to access the invalid object if the target object is destroyed before the observer. But no matter which kind of problem, as long as carefully designed, maintain a good exit mechanism should not be difficult to solve.

The above is the content of this article on "what is the effect of web Observer Mode". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report