GJM: Design mode-Viewer mode

Source: Internet
Author: User

GJM: Observer mode

Video Address: http://www.imooc.com/learn/415

This course explains the application of the observer pattern in Java projects through a release and subscription case for weather forecasts. It mainly includes the structure of the observer pattern, the two implementations of the observer pattern, the model and the pull model, and when to use the observer pattern.

Observer Mode Combat

Structure and description of the Observer pattern

Learning Observer Pattern Generic code

Viewer mode

Recognize observer patterns

Two ways to implement: Push model and pull model

Using the observer implementations provided by Java

Briefly describe the pros and cons of observers

When to use Observer mode

The definition of the observer pattern

Defines a one-to-many dependency between objects. When the state of an object changes, all objects that depend on it are notified and automatically updated.

The observer receives the message The Observer observes the observer when the observer receives the message and performs its own logical processing

Structure of the Observer pattern

Subject Target Weather

SUBJECT Maintenance Observer List Subject has ADD Delete

Subject Execute Notify () = Subject Observer "Update ()" After receiving the target message

Structure diagram

subject{+add (Observer) + Delete (Observer) + Notify ()} <== ConcreteSubject [target message]

Subject =-+subject-> observer{+ Update ()} <== Concreteobserver interface logic implementation class

GJM: Design mode-Viewer mode

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.