Component Interface (API) design Guide [4]-notification (notifications)

Source: Internet
Author: User

* Return to Table of contents read other chapters: http://blog.csdn.net/cuibo1123/article/details/39894477


Notice (Notifications)

The notification is the other half of the trust agreement. My position is that if you use a trust agreement (which you should use in all appropriate places), you will add a notification of the same functionality so that it provides a complete delegation/notification scheme.

In Mgtilemenu, you can find the interface file about the notification: Mgtilemenucontroller



Rule 23: Notification follows delegate method

There is a natural correspondence between the delegate method (the appropriate, not the data source method) and the notification. You can use them anywhere in your code to achieve exactly the same purpose.

If you have a delegate about the occurrence of an event, you should usually also provide a notification of the same purpose. Even if the delegate method is removed, the user can still use the notification to achieve the corresponding function.

The parameters of the delegate method should match the ' UserInfo (notification added) ' content of the notification, a significant difference between the notification and the direct pass parameter in the delegate, which usually requires loading the information into the dictionary (nsdictionary).

Delegate method:

- (void)Tilemenuwilldisplay:(Mgtilemenucontroller *)Tilemenu;
- (void)Tilemenudiddisplay:(Mgtilemenucontroller *)Tilemenu;

The corresponding notification:

extern NSString * mgtilemenuwilldisplaynotification ;
extern NSString * mgtilemenudiddisplaynotification ;


Rule 24: Don't skimp ' userInfo (notice added value) '

Enough information to notify the object. Keep in mind that the notification sink may (almost always) not hold a reference to a delegate or data source component.

Ask yourself what is useful and provide the appropriate information. At the very least, you must ensure that the parameters provided to the corresponding delegate method are included in the UserInfo object.

Delegate method:

- (void)Tilemenu:(Mgtilemenucontroller *)TilemenuWillswitchtopage:(Nsinteger)pagenumber;
- (void)Tilemenu:(Mgtilemenucontroller *)TilemenuDidswitchtopage:(Nsinteger)pagenumber;

The corresponding notification:

// Notice UserInfo contains a key "Mgpagenumber"
#defineMGPageNumberKey @ "Mgpagenumber"
extern NSString * mgtilemenuwillswitchtopagenotification ;
extern NSString * mgtilemenudidswitchtopagenotification ;



Rule 25: Test the hell

Finally, everything has been known to everyone. Specialization in Software engineering 101th: Make sure it does work.

Whether to use formal TDD (test-driven development) depends on you, but the test itself is impossible to do comprehensively. Each of the thousands of combinations of delegate methods, each notification, and each custom point may have problems.

In the event of a defect, you should first find and fix them. If you are in a hurry, you can cut the function. You are bound to be troubled by the problem of bug-free online.


Read the next section: http://blog.csdn.net/cuibo1123/article/details/39894477

-------------------------

" api Design "
Span style= "COLOR:WINDOWTEXT;" >        author : matt Gemmell
        original link : http:/ /mattgemmell.com/api-design/

The Chinese version is xoneday translate
        Welcome to Translator blog: Http://blog.xoneday.com        @xoneday one day

If this translation brings you help, I hope you can download my APP to support me:
watercress reading: https://itunes.apple.com/cn/app/id695492935
Memo Clip: https://itunes.apple.com/cn/app/id580552733

Memo Clip watercress Reading


* Reprint statement: Please do not Delete the content of the author/translator information and Support section, if you do not accept this clause please do not reprint.


Component Interface (API) design Guide [4]-notification (notifications)

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.