In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, Xiaobian will bring you about the role of Observer and EventListener. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
Java.util.Observer
The observer is relatively simple, with only two roles: observer and observed.
observer
We just need to extend an Observable abstract class and implement an Observer interface to use observers. The subscription and distribution process is as follows:
First, the observed adds the observer.
Then, the observed notifyobservers notify the observed, using object to pass parameters
Finally, the Observer interface implemented by the observer will have an update callback, in which two objects are received, one is the observed and the other is the object parameter.
Java.util.EventListener Event Listeners
Event listeners are older and more complex, requiring event sources, event objects, event listener interfaces, and event listener implementation classes.
event listener
By comparison, it is found that the observer implementation is relatively simple, and the subscription and distribution work is implemented in Observable. The maintenance of the observer queue and the notification to the observer have been implemented, and developers can call it directly.
In addition, when the observed distributes events, it directly calls the update function of the Observer interface.
The event listener implementation is complex, requiring its own listener queue maintenance, its own listener notification, and so on.
In addition, when the event source distributes the event, it needs to pass an EventObject event object through handleEvent (the event object also wraps the event source). The event listener receives this event object and processes it again.
The above is what the role of Observer and EventListener shared by Xiaobian is. If you happen to have similar doubts, you may wish to refer to the above analysis for understanding. 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.