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 is the structure of the web Observer pattern?

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Today, I would like to share with you the relevant knowledge about the structure of web Observer mode. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Intention

Define an one-to-many notification method that can notify multiple recipients when the state of the monitoring object changes.

motivation

A common practice of object-oriented design and programming is to subdivide the functions of the system and then encapsulate them into separate classes. But even so, some kind of association between classes needs to occur when these classes are grouped together to form a system. As the receiver of data, the ideal state is not to limit the type of data sender, in other words, to receive data from any sender class. This part is the scope of the adapter pattern. This article is about another perspective, that is, the sender's point of view. As a sender, it is ideal to send data to any receiver, regardless of the type of receiver. This situation is the observer model that we are going to explain today.

structure

Observer mode can be used when an object needs to interact with an unspecified type or number of objects. The interaction here can be communication or calling each other's functions, and there is no essential difference between the two.

As the initiator of the notification, the target class Subject needs to manage the recipient of the notification. On the one hand, the management here refers to the need to maintain the data structure that holds the recipient object, and on the other hand, it also means that it needs to provide an interface to add and delete notification objects to the data structure. In addition, the target class needs to implement an interface that notifies recipients of all interactions.

The observer class Observer defines an interface to accept notifications. This interface is required when the target class issues notifications.

The concrete target class ConcreteSubject derives from the target class Subject and implements the function at the application level. The notification interface of the base class is used to notify when the state of the target class changes.

The observer class ConcreteObserver implements the accept notification interface declared by the observer class Observer. When the notification of the target class is received, the concrete observer class obtains the state of the target class according to its own needs and makes the necessary response according to this state.

These are all the contents of the article "what is the structure of the web Observer pattern?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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