首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

设计形式(观察者模式)

2013-09-17 
设计模式(观察者模式)观察者模式发布者订阅者Subject.javapublic class WeatherStation{public static vo

设计模式(观察者模式)

观察者模式=发布者+订阅者

Subject.java

public class WeatherStation{     public static void main(String[] args){     WeatherData weatherData = new WeatherData(); CurrentConditionsDisplay currentDisplay= new CurrentConditionsDisplay(weatherData);  currentDisplay._setM(80,65,30.4f); currentDisplay.display();}}

当然,以上阐述有个bug,因为观察者模式就是默认通知所有“订阅者”的。根据需要来设计了。

热点排行