ݺߣ
Submit Search
[ʥ˼][Java SE]Observer
?
1 like
?
443 views
ArBing Xie
Follow
1 of 14
Download now
Download to read offline
More Related Content
[ʥ˼][Java SE]Observer
1.
All Rights Reserved
2.
? ۲ģʽһһԶϵ
ö۲߶ͬʱijһ ״̬Ϸ仯ʱ ֪ͨй۲߶ܹԶ Լ
3.
? ۲ģʽ C
ɫжԹ۲߶ñ һУÿɫ Ĺ۲ߡṩһӿڣ Ӻɾ۲߽ɫһһ ӿʵ֡ C ۲߽ɫΪоĹ۲߶һ ӿڣڵõ֪ͨʱԼ
4.
? ۲ģʽ C
ɫھڲ״̬ıʱ еǼǹĹ۲߷֪ͨ ɫͨһʵ֡ C ۲߽ɫýɫʵֳ۲߽ɫ Ҫĸ½ӿڣԱʹ״̬ ״̬ЭҪ۲߽ɫ Աһָɫáͨ һʵ
5.
? ʵԼĹ۲ģʽ
6.
? ۲ģʽJavaеĵλҪ ? JDKҲṩ˶Թ۲ģʽ֧
7.
? ObservableڴԹ۲ij
ֵࡣĶ 仯ʱ۲౻֪ͨ۲ʵ ֶupdate( )Observerӿڡ һ۲֪ͨһ۲ ıʱupdate( )á
8.
? һ۲Ķ
һıˣsetChanged( ) ڶ֪ͨ۲ĸıʱ notifyObservers( )ڹ жupdate( )ĵáע⡪ ڵnotifyObservers( )֮ǰûе setChanged( )Ͳʲô update( )֮ǰ۲ setChanged( )notifyObservers( )ַ
9.
? עnotifyObservers()ʽһִ
вһûСò notifyObservers( )ʱö update( )Ϊڶ update( )һnull ʹõڶʺӦó κ͵Ķ
10.
? Ϊ˹۲һɹ۲Ķʵ
Observerӿڡӿڽ ʾһ C void update(Observable observOb, Object arg) C observObDZ۲Ķarg notifyObservers( )ݵֵ۲ ˸ı䣬update( )
11.
? һ˵ɹ۲ӡóһ
Watcher࣬ʵObserverӿڡص BeingWatched̳ObservableBeingWatched counter( )÷Ǵһֵָʼݼ ÿμıʱnotifyObservers( )ã ǰļΪݸnotifyObservers( ) Watcherеupdate( )ãʾǰļ ֵmain( )ڣֱobservingobservedWatcher BeingWatchedȻobservingӵ observedĹ۲бζÿcounter( ) notifyObservers( )ʱobserving.update( )
12.
? μ ObserverDemo.java
13.
? ж۲
ʵ۲ಢҽÿе һӵBeingWatched۲б Сڶ۲ȴֱΪ0
14.
? μ TwoObservers.java
Download