继承和组合
1)继承和组合都有类似的作用,但是两者使用场合不同:
继承:"XXX是XXX" (比如:狗是动物)
组合:"XXX拥有XXX" (比如:学生拥有成绩)
2)组合的使用;
【例】
//定义一个成绩类
@interface Score : NSObject
{
int _cScore;
int _ocScore;
}
@implementation Score
@end
//【方法一】定义一个学生类
@interface Student : NSObject
{
//组合
Score* _cScore;
int _age;
}
@end
@implementation Student
@end
|
|