Delegate mode
Tip
The delegate object should not be retain
The class that implements the delegate pattern should:
- Has an instance variable named Delegate_ to refer to the delegate.
- Therefore, accessor methods should be named Delegate and setdelegate:.
- 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