I. Categories
Adds a new method to a known class without breaking the encapsulation. Known classes can be classes of custom classes and systems.
1. Realization and Declaration of class purpose
Build a student class and add the category
(1). Declaration (in student+working. h )
The original class must be introduced, here is the Studnet class .
(2). Implementation (is in student+working. m in)
Note the introduction.
2. Use of class purposes
I. Add an instance variable to the class item
J. Multiple classes can be added to a class, but the class name and method name cannot be duplicated
K. Cannot override class intent method arbitrarily
3. Limitations of Class Purpose
I. Overriding the method of the parent class in the class may cause the super message to break because the method in the class takes precedence over the parent class.
J. Cannot add an instance variable in the class.
Two. Extension
The private method is declared by adding a class to the implementation file of its own class, extending the equivalent of an anonymous class item.
1. Disclaimer
In the studnet.m file, above the @implementation, the method is not required to implement the
The extension does not provide a name that must be implemented, and the supplied name may not be implemented.
2. Implement
In the studnet.m file, implement the method in @implementation and @end.
The results that were called and printed in MAIN.M are as follows:
Three. Agreement
Declare some methods to be implemented by other classes, or add methods to classes
1. Declaring an agreement
In the file
2. In the header file of the Import protocol
3. Adoption of agreements in documents
4. And implement the methods in the protocol in the file
OC language category, extension, protocol