IOS Design Pattern Learning (12) Observer

Source: Internet
Author: User

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.

 

Related Article

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.