Memory management of OC
IOS7 used the MRC Manual memory Management and now uses ARC automatic memory management, which typically does not present a memory leak issue.
Packaging
Encapsulation is the choice of protecting your own code. The interfaces that will be used by others are left to be seen, and others are hidden. Increased readability, maintainability, and extensibility of the code.
Put the code for others to see in the interface (. h or. m), not to let the watch be placed in the implementation. This is the encapsulated object.
Inherited
Subclasses can inherit properties and methods that are not private to the parent class.
Advantages of Inheritance: 1. Code reuse 2. Making rules 3. For polymorphism
Disadvantages of Inheritance: 1. Improved code complexity, maintainability, and complexity by 2. The encapsulation of the class is broken (the teacher says if it's not for polymorphism, less inheritance)
Example:
TRAnimal.h
1 #import<Foundation/Foundation.h>2 3 @interfaceTranimal:nsobject4@property NSString *name;5@propertyintAge ;6-(ID) Initwithname: (nsstring*) name Andage: (int) age;7-(void) eat;8-(void) sleep;9 @end
tranimal.m
1 #import "TRAnimal.h"2 3 @implementationTranimal4-(ID) Initwithname: (NSString *) name Andage: (int) Age5 {6 if(self =[Super init])7 {8Self.name =name;9Self.age =Age ;Ten } One returnSelf ; A } --(void) Eat - { theNSLog (@"Animal%@ Eat", self.name); - } --(void) Sleep - { +NSLog (@"Animals%@ Sleep", self.name); - } + @end
TRDog.h
1 #import "TRAnimal.h"2 3 @interfaceTrdog:tranimal4@propertyintweight;5-(ID) Initwithname: (NSString *) name Andage: (int) Age Andweight: (int) weight;6-(void) Watchhome;7 @end
Trdog.m
1 #import "TRDog.h"2 3 @implementationTrdog4-(ID) Initwithname: (NSString *) name Andage: (int) Age Andweight: (int) Weight5 {6 if(self =[Super Initwithname:name Andage:age])7 {8Self.weight =weight;9 }Ten returnSelf ; One } A-(void) Watchhome - { -NSLog (@"dog%@ is housekeeping .", self.name); the } --(void) Eat - { - [Super eat]; +NSLog (@"dog%@ in Chew Bones", self.name); - } + @end
In the dog Class I rewrote the Eat method and added the Watchhome method.
Override of Method:
Subclasses satisfy the same method name as the parent class, have the same parameter type, return the same value, or override the parent class. If the parent class method is overridden, the method of the child class is called, otherwise the method of the parent class is called.
Polymorphic
Polymorphism is the way that a parent class uses a child class constructor. See more:http://www.cnblogs.com/wendingding/p/3705428.html
(object-c) Learning Notes (iii)--OC memory management, encapsulation, inheritance, and polymorphism