Observer mode of Java design pattern

Source: Internet
Author: User

Observer mode is also called Observer mode, which is one of 23 software design patterns proposed by GOF. Observer mode is one of the behavioral patterns, it is the role of an object when the state changes, can automatically notify other associated objects, automatic refresh object state.

This article describes the concept, usage, and how to use the Observer pattern in the design pattern for the development of the Observer pattern.

The concept of observer mode

Observer mode is one of the behavioral patterns, it is the role of an object when the state changes, can automatically notify other associated objects, automatic refresh object state.

The Observer mode provides a means of synchronizing communication between an object and other objects that depend on it.

Typical application of observer model

-Listen for external events in event-driven programming

-Listening/monitoring state changes of an object

-In the Publisher/Subscriber (Publisher/subscriber) model, when an external event (a new product, the presence of a message, and so on) is triggered, the subscriber in the notification mailing list

Advantages of the Observer model

-Synchronization between objects can be communicated

-You can notify one or more associated objects at the same time

-The relationship between objects is loosely coupled and interdependent

Structure of the Observer pattern

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.