In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is the java Observer Mode". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The concept of ① Observer Model
The Observer pattern (Observer), also known as publish-subscribe pattern (Publish/Subscribe), defines an one-to-many dependency between objects, so that whenever an object changes its state, all objects that depend on it are notified and updated automatically. The structure diagram of UML is as follows:
For example, the relationship between the weather station and the weather bulletin board. However, if the report board wants to obtain the data of the observation station, it can be registered and added to the observer list of the observation station, which can automatically transmit the data to the weather report board when the data of the observation station is updated.
WeatherData acts as an intermediary between weather stations and observers. After obtaining the data from the weather station, WeatherData sends the data to the observer.
The structure of the ② Observer Model
The main roles of the observer model are as follows:
Abstract topic (Subject) role: also known as the abstract target class, it provides an abstract method for saving the aggregate class of the observer object and for adding and deleting the observer object, and for notifying all observers.
Concrete Subject role: also known as the concrete target class, which implements the notification method in the abstract goal and notifies all registered observer objects when the internal state of the specific topic changes.
Abstract observer (Observer) role: an abstract class or interface that contains an abstract method that updates itself and is called when notified of a change to a specific topic.
Concrete Concrete Observer role: implements abstract methods defined in the abstract observer to update its state when notified of a change to the target.
Advantages and disadvantages of ③ Observer Model
Advantages:
It reduces the coupling relationship between the target and the observer, which is an abstract coupling relationship.
A trigger mechanism is established between the target and the observer.
Disadvantages:
If an observed object has many direct and indirect observers, it will take a lot of time to notify all the observers.
The dependency between the target and the observer has not been completely removed, and circular references may occur.
That's all for "what is the java Observer Mode?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.