一、间接(inderection)
即使用某种东西指向你想要的对象,或使用某事物代为办理某种工作
1、变量与间接
举例代码:
int i;
int count = 5;
for(i = 1; i <= count; i++){
}
其中count就是间接
2、文件名的间接
将处理内容保存到外部文件,使用文件流读取
二、在面向对象编程中使用间接
// Draw the shapes
void drawShapes (id shapes[], int count)
{
} // drawShapes
代码解释:
1、
2、
三、Objective-C中的OOP
@interface接口,定义类的公共接口
创建类对象之前,Objective-C编译器需要读取类内部信息,使用@interface可以把信息传递给编译器
示例代码:
@interface Circle:NSObject
{
}
- (void) setFillColor : (ShapeColor) fillColor;
- (void) setBounds : (ShapeRect) bounds;
- (void) draw;
@end //Circle
Objective-C方法可以返回与C相同的类型:标准类型(整型、浮点型和字符型)、指针、对象引用和结构
中缀符(infix notation)
Objective-C中有中缀符的语法,即方法的名称及其参数时和在一起的
例如,调用方法时将参数传入
[circle
带两个参数的方法调用
[textThing
C中调用函数则直接把参数放在方法名之后,例:setTextThingValueColor(textThing, @"hello there" , blue);
@implementation实现,即接口的实现类
举例代码:
@implementation Circle
- (void) setFillColor : (ShapeColor) c
{
}//setFillColor
-(void) setBounds :(ShapeRect) b
{
}//setBounds
-(void) draw
{
}//draw
实例化(instantiation)对象
创建新对象需要发送new消息
举例代码:
int main (int argc, const char * argv[])
{
}