Design tips for iOS development agents

Source: Internet
Author: User

1, about the proxy object design tips

In designing a class, you need to get the dynamic data from the outside by proxy and protocol. Then there are two ways to design the use of proxies here.

< The first method > is also more common:

In the class you are designing, declare a proxy property

  

And then when it's used externally,

  

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

< The second method > Adds a proxy object's parameters to the constructor of the class object you want to design, so that if you want to create this object, you must add a proxy object.

  

So externally when creating this object, using this method implicitly requires you to add this proxy object

  

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, it warns you to implement the Protocol method.

Summary: The first method is familiar to everyone, but for the second method is also some special circumstances necessary design method, this method is also the source of self-development encountered in a situation: a class need to judge the current network state of the device, but if the first method of designing this class, the client uses this class, May ignore set proxy object, this is not rigorous, is easy to make a bug, so the second design method, you can restrict the user side in the use of this object must implement set proxy object.

The specific use of method one or method two, or according to actual development to decide and design.

Design tips for iOS development agents

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.