写点什么

Go 的观察者模式

用户头像
baiyutang
关注
发布于: 刚刚

译者:baiyutang

原文:https://medium.com/@srinjoysantra/observer-pattern-in-go-aebbe83785b5



This is the second chapter of Head First Design Patterns book. Though the book has code snippets in Java, my attempt here is to implement the problem discussed in Go. Without further ado, let’s understand the use-case.

The problem statement

We are told to design a weather monitoring application. It consists of 3 sections

  1. Weather station : to record humidity, temperature and pressure

  2. Weather data : tracks data from the weather station and forwards it to the displays

  3. various display elements :

  • current conditions,

  • weather statistics,

  • simple forecast, and

  • heat index calculator


UML 类图


输出

Current conditions: 80.0F degrees and 65.0% humidity.Avg/Max/Min temperature = 80.0/80.0/80.0Forecast : Improving weather on the way!Heat index is 82.955345Current conditions: 82.0F degrees and 70.0% humidity.Avg/Max/Min temperature = 81.0/82.0/80.0Forecast : Watch out for cooler, rainy weather!Heat index is 86.901260Current conditions: 78.0F degrees and 90.0% humidity.Avg/Max/Min temperature = 80.0/82.0/78.0Forecast : More of the same.
复制代码


发布于: 刚刚阅读数: 3
用户头像

baiyutang

关注

广州 2017.12.13 加入

Microservices | Golang | Cloud Nitive | “Smart work,Not hard”

评论

发布
暂无评论
Go 的观察者模式