OC, oc Language
I. Encapsulation
1> encapsulation Definition
- Hides the attributes and implementation details of an object and only exposes the interface to control the read and modify access levels of attributes in the program.
2> advantages of encapsulation
- You can use the set method to prevent improper values for member variables.
- Only public interfaces are provided to the outside, and the operation process of member variables is blocked.
- External users can indirectly manipulate member variables through interfaces without having to focus on internal details.
3> set and get Methods
Ii. Inheritance
1> inherited Definitions
- An object uses the attributes and methods of another object directly, and extends its own unique attributes and methods.
2> advantages and disadvantages
3> basic usage
- You can use the member variables and methods inherited from the parent class.
- You can expand your own methods as needed
- You can use the same name method in the subclass to override the method of the parent class.
- When calling a method, find the method in the current class. If the method cannot be found, find it in the parent class.
4> usage notes
- User-Defined classes generally inherit from the root class in the system, such as NSObject.
- The inheritance of OC language is single inheritance
- Only non-private member variables and methods of the parent class can be inherited.
- Inheritance cannot reduce the member variables and methods in the parent class.
- Member variables with the same name as the parent class are not allowed in subclass
- The parent class must be declared before the subclass.
5> inheritance and combination
6> self and super
Iii. Polymorphism
1> concept of dynamic binding
- Determine the actual type of the referenced object during the execution of the program, and call the corresponding method based on the actual type.
2> basic usage
- Polymorphism usually refers to multiple forms
- Represents a parent class pointer pointing to a subclass object
- Dynamic binding of Classes
3> advantages and disadvantages
4> usage notes
- Polymorphism must be based on inheritance.
- During running, the system dynamically detects the real object pointed to by the pointer.
- The OC language is a weak syntax. You can use any type of pointer to point to a known object and only issue a warning.