前言
例如,有如下代码:
Person对象的定义如下:
@interface Person : NSObject
{
Car *_car;
}
– (void)setCar:(Car *)car;
– (Car *)car;
– (void)drive;
@end
@implementation Person
– (void)setCar:(Car *)car
{
[_car release];
_car = [car retain];
}
– (Car *)car
{
return _car;
}
– (void)drive
{
NSLog(@"走,去拉萨。。。);
[_car run];
}
– (void)dealloc
{
[_car release];
NSLog(@“人挂了。。。”);
[super dealloc];
}
@end
Car类的定义如下:
@interface Car : NSObject
{
int _speed;
}
– (void)setSpeed:(int)speed;
– (int)speed;
– (void)run;
@end
@implementation Car
– (void)setSpeed:(int)speed
{
_speed = speed;
}