1. Inheritance Definitions
Common Parent Class Usage scenario: when there are some of the same characteristics and behaviors between multiple classes, in order to prevent multiple classes from writing duplicate code, create a new public parent class that fills in the same characteristics and behaviors in multiple classes in the parent class to inherit from multiple classes.
2. Inheritance characteristics
*. Inherited content: Father all the strength variables and methods
*. Ownership of inherited content: inherited content is its own, but from the parent class,
*. Only single inheritance is allowed in OC, that is, a class can have only one parent class,
*. Inheritance has transitivity. A inherits from B,b inherits all the contents of B and C from C,a.
*. Inheritance does not have reciprocity; cannot inherit b,b a again.
*. The inherited content should be meaningful.
*. Inheritance belongs to one of the three main features of object-oriented.
3. Inheritance usage:
Note: Inherited becomes a parent class, or a superclass. (Super Class) (subclass) Subclass
Subclasses can directly use some of the characteristics and behaviors of the parent class,
[e-Mail protected] Application
1. In the. h file, the @class declaration needs to be in the. m file in the import
MAN.M implementation file
5. Traversing the constructor
Traversal constructor: A way to quickly create an object. It is essentially an initialization method that has been encapsulated for ease of external use.
Convenience Builder: + number method
Example: 1. Declaration
+ (ID) Studentwithscore: (NSString *) name withage: (nsinteger) Age withsex: (NSString *) Sex withnumber: ( Nsinteger) Number Withscore: (cgfloat) score;
2. Implement
<span style= "color: #000000;" >+ (ID) Studentwithscore: (NSString *) name withage: (nsinteger) Age withsex: (NSString *) Sex withnumber :(nsinteger) Number Withscore: (cgfloat) score { Student *stu = [[Student alloc] Initwithname:name withage: Age withsex:sex withnumber:anumber Withscore:ascore]; return Stu;} </span>
3.creates an instance object by traversing the constructor.
<span style= "color: #000000;" >student *stu = [Student studentwithscore:23.8 withage:23 withsex:@ "man" withnumber:234234 withscore:34.5 ];</span>
"Learn the path of iOS: Object-c" inheritance, convenience builder. NSString applications