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