IOS development agent design tips and ios development tips

Source: Internet
Author: User

IOS development agent design tips and ios development tips

 

 

1. Tips on proxy Object Design

When designing a class, you need to obtain the required dynamic data from the outside through proxy and protocol. There are two methods to design proxy here.

<Method 1> is also common:

Declare a proxy attribute in the class you designed

Then, when used externally

Finally, follow the Protocol and implement the Protocol according to the <... Protocol> Protocol.

<Method 2> Add a proxy object parameter to the constructor of the class object you want to design. The purpose is to create the proxy object as needed, you must add a proxy object.

In this way, when creating this object, the external user needs to add this proxy object forcibly by using this method.

Then, because the current object is set as a proxy through self, if the proxy object follows the Protocol but does not implement the Protocol method, it will warn you to implement the Protocol method.

Conclusion: The first method is familiar to everyone, but the second method is also necessary for some special situations. This method is also a situation encountered in source self-development: the Network Status of the current device needs to be determined in real time in a class. However, if you use the first method to design this class, the client may ignore setting proxy objects when using this class, this is not rigorous and is prone to bugs. Therefore, the second design method can be used to restrict the user end from setting proxy objects when using this object.

Use method 1 or Method 2: Determine and design based on actual development conditions.

 

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.