1 Preface
The observer mode is also called the publish-subscribe mode. As its alias implies, it looks like a magazine subscription. When subscribing to a magazine from a magazine publisher, the reader provides the name and mailing address to the publisher so that the new issue can be delivered to the reader. The publisher ensures that the correct magazine is delivered to the correct address. In general, the reader will not receive any magazines that he has not subscribed. This is exactly how the observer mode works.
2. Details
2.1 Brief Introduction
The observer registers himself (subscribes) to a specific notification (magazine) by means of a notifier (publisher ). When there is a notification, the observer only obtains the notification subscribed to by the notification receiver.
Defines a one-to-many dependency between objects. When the status of an object changes, all objects dependent on it are notified and automatically updated.
2.2 When to use
(1) Two abstract types are mutually dependent. By encapsulating them in their own objects, they can be individually changed and reused.
(2) changing an object requires changing other objects at the same time without knowing how many objects need to be changed.
(3) An object must notify other objects without knowing what other objects are.
2.3 use in the Cocoa Touch framework
Key-Value Observing ).
3 conclusion
The above is all content and I hope it will help you.