Inheritance Features
only single inheritance is allowed in OC .
The class of the parent class is called the root class, and the root class in OC is nsobject( ancestor ).
Inherited content: All instance variables and? methods.
If the subclass is not satisfied? The implementation of the parent class? Method can be overridden (overwrite)? Method of the parent class .
Inheritance has transitivity
Completion of initialization method
-(void) init
{
Send the INIT message to Super: Executes the Init method implemented in the parent class
self = [super init];
if (self)
{
Initialize settings
}
Returns the object that was initialized for completion
return self;
}
The above is called the specified initialization method
Specifies that the initialization method has more than one other initialization method with multiple
Convenience Builder (+ method)
Returns an instance of this type, with the method name beginning with the class name.
Internal implementation: Encapsulates the Alloc and initialization methods. It's more concise.
1. Declaration and implementation of the convenience builder
+ (person *) Personwithname: (nssting *) name
{
Person *p = [[Person alloc] initwithname:name]
return p;
}
2. Create objects using the convenience builder
Person *p = [Person personwithname:@ "ianhao.cn"];
Inheritance, initialization, method, convenience builder