Advantages of delegate :
1. Very strict grammar. All events that will be heard must be clearly defined in the delegate protocol.
2. If one of the methods in delegate is not implemented then a compile warning/error will appear
3. The protocol must be defined within the scope of the controller
4. The control flow in an application is traceable and recognizable;
5. In one controller you can define multiple different protocols, each with a different delegates
6. There is no third-party object required to maintain/monitor the communication process.
7. The return value of the protocol method that can receive the call. This means that delegate can provide feedback to the controller
Disadvantages :
1. Need to define a lot of code: 1. Protocol definition; 2.controller delegate property; 3. Implement delegate method definition in delegate itself
2. When releasing the proxy object, be careful to change the delegate to nil. Once the setting fails, the call to dispose of the object will show memory crash
3. There are multiple delegate objects in a controller, and delegate is in compliance with the same protocol, but it is still difficult to tell multiple objects the same event, but it is possible.
advantages of notification :
1. Do not need to write how much code, implementation is relatively simple;
2. For a given notification, multiple objects can react, that is, 1-to-many ways to achieve a simple
3.controller is able to pass a context object (dictionary), and the context object carries a custom message about sending notifications
Disadvantages :
1. In the compilation period will not check whether the notification can be properly handled by the observer;
2. When releasing the registered object, you need to cancel the registration in the Notification Center;
3. In the commissioning of the application of the work and control process difficult to track;
4. A third party is required to manage the connection between the Controller and the Observer object;
5.controller and observers need to know the notification name and Userinfodictionary keys in advance. If these are not defined in the work interval, then there is an unsynchronized situation;
6. After the notification is issued, the controller cannot obtain any feedback from the observer.
advantages of KVO :
1. The ability to provide a simple way to achieve synchronization between two objects. Example: synchronization between model and view;
2. Be able to respond to changes in the state of objects not created by us, i.e. internal objects, without changing the implementation of the inner object (SKD object);
3. Ability to provide the latest value of the observed properties and previous values;
4. Use key paths to observe attributes, so you can also observe nested objects;
5. The abstraction of the observed object is completed because no additional code is required to allow the observed value to be observed
Disadvantages :
1. The attributes we observe must be defined using strings. Therefore, the compiler will not appear warning and check;
2. Refactoring the property will cause our observation code to be no longer available;
3. A complex "IF" statement requires that the object is observing multiple values. This is because all the observation code is directed by a method;
4. You do not need to remove the observer when releasing the Observer.
1. Efficiency is certainly delegate higher than Nsnotification.
The delegate method is more direct than notification, and the most typical feature is that the delegate method often needs to focus on the return value, which is the result of the delegate method. For example,-windowshouldclose: You need to be concerned with whether the return is yes or No. So the delegate method often contains should, a very expressive word. Just like you do my delegate, I'll ask you I want to close the window would you like to? You need to give me an answer and I will decide what to do next, based on your answer. On the contrary, notification's biggest feature is not caring about the recipient's attitude, I just put out the notice, you accept not accept is your thing, and I do not care about the results. So notification often use did this word, such as nswindowdidresizenotification, then Nswindow object release this notification after nothing will not wait for the response of the recipient.
2. The difference between KVO and nsnotification:
Like delegate, the role of KVO and Nsnotification is also a class-to-class communication, unlike the Delegate 1) both are responsible for giving notice, the rest of the matter, so there is no return value; 2) delegate is just one-to-one, And these two can be a couple more. The two also have their own characteristics.
The difference between KVC, KVO, Nsnotification, delegate and the answer to the new company