<1> inheritance and polymorphism @ Class complex Declaration class (same as C ++) sub-class function member super access parent class is similar to C ++ 1. add a new method 2 to the subclass by inheritance. add a new member to the subclass through inheritance 3. realize polymorphism through inheritance (implementation is relatively simple, and use the ID generic type as the parent class) 4. reload 5. abstract class Abstract: it is easier to create a subclass. It provides a public interface for processing all derived subclasses. Abstract METHODS develop standard protocols, and standard subclasses must be implemented. 6. General type ID. No type check will be performed during compilation, and the specific type will be dynamically bound during runtime to indicate errors. Static types indicate errors during compilation. In addition, they can improve program readability. 7. Several Methods for Processing dynamic types mysquare is an example of the square class. [Square class] // obtain the class object from the square class [mysquare class] // obtain its class from the mysquare object [obj1 class] = [obj2 class] // determine two objects whether it belongs to the same class [mysquare is memberof: [square class] // determines whether mysquare is an instance of square @ selector (alloc) // generates a value of the SEL type for the alloc method [Square respondsto @ selcetor (alloc)] = Yes // determine whether the square Class responds to the alloc class method [Square instancerespondtoselector: @ selector (Action)] // check whether the square instance responds to the Action Method eg: if ([Square instancerespondtoselector: @ Selector (Action)] = Yes) [mysquare extends mselector: @ selector (Action)] // apply the action method [Square issubclassofclass: [rectangle class] = Yes // determines whether Square is a rectangle subclass <2> @ try Exception Handling-(void) action {... if (array out-of-bounds) nsexception * E = [nsexception exceptionwithname: @ "out of array" Reason: @ "address is invalid" userinfo: Nil] @ throw E; // throw an exception} @ try {[mysquare Action]; // try to execute the mysquare Action Method} @ catch (nsexception * ti On) {// capture exceptions. You can also derive the nsexception subclass and redefine the details of nslog (@ "caught % @", [Exception name], [Exception reason]); // The name and cause of the exception} @ finally {// no matter whether the exception occurs or not, you must execute <code block >}< 3> the protocol and classification can extend the class method, you do not need to create a subclass or the source code of the subclass class, but it will affect the subclass. @ Interface square (mathops)-(void) print; // Add a new method. Unlike the default protocol, the unforced @ end protocol is a list of methods shared by multiple classes, similar to abstract methods of abstract classes, subclass must implement this method. @ Protocal <nscoding> // nscoding protocol-(void) copywithzone; // by default, @ optional must be implemented. // optional, users of this Protocol are not forced to implement the print-(void) print function; @ required // indicates that cout-(void) cout must be implemented; @ protocal <nscopying> // nscopying protocol-(void) copy; @ end @ interface addressbook: nsobject <nscopying, nscoding> // multiple protocols can be used @ interface square (mathops) <nscopying, nscoding> // protocol can also be used for classification