Observer patterns in weather forecasting projects

Source: Internet
Author: User
The application scenario for the project is that the meteorological Bureau needs us to build a system with two billboards that show the current real-time weather and the weather forecast for the next few days. When the Meteorological Bureau publishes new weather data, the weather data displayed on the two bulletin boards must be updated in real time. The meteorological Bureau also asked us to ensure that the program was sufficiently scalable, since a new bulletin board might be added at a later stage. Principle:

  

We implemented the theme interface with Weatherdate, two bulletin boards currentconditionsdisplay and Forcastdisplay realized the observer and Displayelement interfaces, In their constructor, the Registerobserver () method in Weatherdata is called to register themselves as observers and save them in a collection. When the observer is the Weatherdata data change, the Notifyobserver () method is called to notify the Observer, that is, two bulletin boards, and call the Updata () method to update their data.

Advantages of this mode:

1. The Observer (bulletin board) and the Observer (Meteorological Office) are fully decoupled, the observer only knows the abstract interface of the Observer list, and the observer does not know the specific observer.

2. Notifications are sent by the Observer, and all registered observers receive information that can implement the broadcasting mechanism.

 

Finally attach the source code address of the program: Https://github.com/BaronZ88/DesignPatterns/tree/master/src/com/baron/patterns/observer

Observer patterns in weather forecasting projects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.