Requirement: How to extend some methods to the class without changing the original class model? There are 2 different ways
> Inheritance
> Category (category)
(i) Understand catagory
1.Catagory, can be dynamic for the existing classAdd a new behavior (method), feature extensions, when you extend a class using category, you do not need to create subclasses. Category uses a simple way to implement the modularity of class-related methods, assigning different class methods to different classification files
Category (categories, categories, categories)--(For functional classification, Division of labor, conducive to development, usually named after the function)
2. Example
// Statement @interface class name ( @end// implementation @implementation class names ( Category name )@end
3. created by the New File ,-->os X (under Cocoa)-->objective-c category-->
Note:#import "Dog+yy.h" is to say clearly what the classification is called
/*
The function of classification: You can add some methods to the class without changing the contents of the original class.
Use Note:
1. Classification can only increase the method, cannot increase the member variable
2. member variables declared in the original class can be accessed in the classification method implementation
3. Classification can re-implement the methods in the original class, but will overwrite the original method, will cause the original method can not be used
4. Priority of method invocation: Classification (the last category that participates in compilation takes precedence)--and the original class---The parent class
*/
iOS development OC (ix)--category-categories