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

Source: Internet
Author: User

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


Notice (Notifications)

Notice is half of the trust agreement. My position is that. Suppose you use a trust agreement (which you use in all appropriate places) to add a notification of the same functionality. So that it provides a complete trust/notification scheme.

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



Rule 23: Notify the trailing trust method

In the method of entrustment (appropriate. is not a data source method) and there is a natural correspondence between notifications. You can use them wherever you are in your code. and achieve exactly the same purpose.

Suppose you have a commitment to the occurrence of an event. You should usually also provide a notification for the same purpose. Even if the trust method is removed, the user will still be able to implement the corresponding function by notification.

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

How to entrust:

- (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 practical and provide the corresponding information.

At the very least, you must ensure that the number of references provided to the corresponding delegate method is included in the UserInfo object.

How to entrust:

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

The corresponding notification:

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



Rule 25: Test the hell

In the end, we all know the whole thing.

Software Project Specialization article 101th: Make sure it does work.

Whether to use formal TDD (test driven development) depends on you. But the test itself is unlikely to be comprehensive. There may be problems with each of the thousands of combinations of trust methods, each notification, and each custom point.

In the event of a defect, you should first find and fix them. Suppose you are in a hurry and 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
        http://blog.xoneday.com        @xoneday one day

Let's say that this translation brings you help, and 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: do not delete the content of the author/translator information and Support Section. If you do not accept the terms, 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.