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.