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