Google objective-c Coding style (5) Cocoa mode

Source: Internet
Author: User

Delegate mode

Tip

The delegate object should not be retain

The class that implements the delegate pattern should:

    1. Has an instance variable named Delegate_ to refer to the delegate.
    2. Therefore, accessor methods should be named Delegate and setdelegate:.
    3. Delegate_ objects should not be retain.
Model/view/controller (MVC)

Tip

Detach the model from the view. Detach the controller from the view, model. The callback API uses @protocol.

    • Detach a model from a view: Do not assume that the model or data source is represented. Maintains an abstraction of the interface between the data source and the presentation layer. The view does not need to understand the logic of the model (the main rule is to ask yourself, for an instance of the data source, there may be multiple representations of different states).
    • Detach controller and model, view: Do not put all the "business logic" into the class related to the view. This makes the code very difficult to reuse. Use the Controller class to handle the code, but ensure that the controller does not need to know too much about the logic of the presentation layer.
    • Use @protocol to define the callback API, if not all methods must be implemented, using @optional "(Special Case: When using objective-c 1.0 , ' @optional is not available, you can use categories to define an "informal protocol".

Google objective-c Coding style (5) Cocoa mode

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.