Define a one-to-many dependency relationship between objects. When the state of an object changes, all objects that depend on it are notified and automatically updated. Publish-subscribe model
Object
Abstract subject (Subject)
Concrete Subject (ConcreteSubject)-Publisher
Abstract Observer (Observer)
Concrete Observer (ConcreteObserver)-Subscriber
Applicable scene
When an abstract model has two aspects, one aspect depends on the other. Encapsulate the two in two independent objects so that they can be changed and reused independently
When a change to an object needs to change other objects at the same time, it is not known how many objects need to be changed
When an object must notify other objects, and he cannot assume who the other objects are, in other words, you don’t want these objects to be tightly coupled