In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, Xiaobian will bring you about what the observer model is. The article is rich in content and analyzes and narrates it from a professional perspective. After reading this article, I hope you can gain something.
Observer pattern is an object behavior pattern that defines a one-to-many dependency relationship between objects. When the state of an object changes, all objects dependent on it are notified and automatically updated, thus improving the maintainability and reusability of applications.
Observer pattern is a pattern of object behavior. It defines a one-to-many dependency between objects, so that when an object changes state, all dependent objects are notified and automatically updated. In the observer pattern, the subject is the publisher of notifications, it does not need to know who its observers are when it issues notifications, and any number of observers can subscribe and receive notifications. Observer pattern is widely used not only in the interaction between software interface elements, but also in the interaction between business objects and permission management.
Observer mode perfectly separates the observer from the observed object. For example, the user interface can act as an observer, and the business data is observed. The user interface observes the changes of the business data, and after discovering the data changes, it will be displayed on the interface. One of the principles of object-oriented design is that each class in a system focuses on one function rather than another. An object does only one thing and does it well. The observer pattern draws clear boundaries between modules, improving application maintainability and reusability.
The Observer design pattern defines a one-to-many combinatorial relationship between objects so that when an object changes state, all dependent objects are notified and automatically refreshed.
Observer mode implementation
There are many ways to implement the observer pattern, but fundamentally, the pattern must have two roles: observer and observed. In the previous example, the business data is the observed object and the user interface is the observer. There is a logical connection between the observer and the observed. When the observed changes, the observer will observe the change and respond accordingly. If you use this observation process between the user interface and the business data, you can ensure that there is a clear line between the interface and the data, assuming that the application requirements change and you need to modify the appearance of the interface, you only need to rebuild a user interface, and the business data does not need to change.
Observer mode usage scenarios
An abstract model has two aspects, one of which depends on the other. Encapsulate both in separate objects so that they can be changed and reused independently of each other.
When changes to one object require changes to other objects at the same time, without knowing exactly how many objects need to be changed.
When an object must inform other objects, it cannot assume who the other objects are. In other words, you don't want these objects to be tightly coupled.
The above is what Xiaobian shared for everyone is the observer model, if there is a similar doubt, may wish to refer to the above analysis to understand. If you want to know more about it, 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.