Delegate and notification

Source: Internet
Author: User

Delegate is for the one-to-one relationship, and the reciever can return a value to the sender;

Notification can be targeted at one-to-one/notify/NONE. reciever cannot return the value to sender;

Therefore, delegate is used by sender to receive a function feedback value from reciever, and notification is used to notify multiple objects of an event.


Active delegate and passive notification

1.

Delegate:
Message sender(Sender)Notify recipient(Worker ER)An event is about to happen,DelegateAgree and then the sender responds to the event,DelegateThe mechanism allows the recipient to change the behavior of the sender. Generally, the relationship between the sender and the receiver is a direct one-to-multiple relationship.

Notification:
The sender of the message informs the recipient that the event has occurred or is about to be sent. The recipient cannot in turn affect the behavior of the sender. Generally, the relationship between the sender and the receiver is indirect many-to-many relationship.

2.

Very early, stepwise has a classic articleArticleI did not tell the difference between delegate and icationicationde, but I am sorry that stepwise is offline now.
Simply put,
1.The efficiency must be higher than that of nsnotification.
2. The delegate method is more direct than the notification method. The most typical feature is that the delegate method usually needs to focus on the return value, that is, the result of the delegate method. For example,-windowshouldclose: whether yes or no is returned. Therefore, the delegate method usually contains the word "shocould", which is a very expressive word. That is, if you do my delegate, I will ask you if you want to close the window? You need to give me an answer. I will decide how to proceed based on your answer. On the contrary, the biggest characteristic of notification is that you don't care about the attitude of the recipient. I just release the announcement. Your acceptance or rejection is your business, and I don't care about the results either. Therefore, notification often uses the did term, such as nswindowdidresizenotification. After the nswindow object releases the notification, nothing will happen and it will not wait for the recipient's response.

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.