*******************************************
为什么选择设计模式
*******************************************
看了 head first design pattern,浏览了一下 《大话设计模式》,感觉设计模式的学习会比较有趣,因为能利用现实生活中的故事来理解设计模式。
学习笔记的主要参考书是 head first design pattern,因为完整的只有英文版,所以笔记中会 copy 很多英文原句。
*****************************
气象发布 引发的模式
要做什么?
*****************************
有三个玩家,如下
The three players in the system are the weather station (the physical device that
acquires the actual weather data), the WeatherData object (that tracks the data coming
from the Weather Station and updates the displays), and the display that shows users
the current weather conditions.
简而言之,气象站更新天气预报后,张三能够通过手机看到更新后的天气预报。
中间项 WeatherData 负责连接。
然后,就有任务了
Our job, if we choose to accept it, is to create an app that
uses the WeatherData object to update three displays for
current conditions, weather stats, and a forecast.
零零豆:我要10万精兵,再加10吨战备茅台。
不行,给你的只有
we have to figure out what we need to do. So, what do we know so far?
- The WeatherData class has getter methods for three measurement values: temperature, humidity and barometric pressure.
- The measurementsChanged() method is called any time new weather measurement data is available
- We need to implement three display elements that use the weather data: a current conditions display, a statistics display and a forecast display. These displays must be updated each time WeatherData has new measurements.
- The system must be expandable—other developers can create new custom display elements and users can add or remove as many display elements as they want to the application. Currently, we know about only the initial three display types