1. Composite
1.0 Compounding and inheritance
-"describes the relationship between a class and a class or object and an object in two ways: 1. Inheritance 2. Compound;
-"Inheritance can define a new class with all the functions of the parent class.
-"composite, the object can refer to other objects.
Difference:
-"Compound: has-a Car has a tire (inclusive relationship)
-"Inherited: Is-a A Male is a person (affiliation)
1. 1 Basic syntax examples for compositing
#import "Tire.h" #import "Engine.h" @interface car:nsobject{ //Save the address of the tyre and engine *_engine; Tire *_tires[4];} -(Car *) init;-(void) run;-(void) Setengine: (Engine *) newengine;-(engine *) engine; @end
2. Use of @class keywords
2. 1 Basic concepts and basic grammar
-"@class The role of the keyword: declaring a pre-reference to a class
-"Grammar writing: @class class name;
Note: When class A needs to use the class name of Class B,
We can use @class to declare this class B;
Use @class B in the A.h file of Class A;
In the a.m., use #import "B.h" to import the header file of Class B.
2. The difference between the 2 @class and the #import
- @class is merely a declaration of a single class, equivalent to an extern statement;
- #import is to import the entire header file, equivalent to # include
OC language--recombination and inheritance