前言
1)用面向对象模拟一个案例: 凤姐开车去拉萨。 先找类吧? 人类: 属性:车 行为:开车 车类: 属性:速度 行为:行驶 城市类:
一、车类@interface Car:NSObject { int _speed; } – (void)setSpeed:(int)speed; – (int)speed; – (void)run; @end @implementation Car – (void)setSpeed:(int)speed { _speed = speed; } – (int)speed { return _speed; } – (void)run { NSLog(@“速度为%d的车子,在行使”,self.speed); } //这时候,我们为了监视Car对象的回收过程,是不重写一下dealloc方法啊? – (void)dealloc { NSLog(@“时速为%d的车子,挂了。。。”,self.speed); [super dealloc]; } //默认情况下,这是不是1个ARC啊,我们应该先把ARC关掉 @end
二、人类