什么时候使用分类
当1个类的方法很多很杂的时候,当1个类很臃肿的时候,
那么这个时候我们就可以使用分类,将这个类分为多个模块,将功能相似的方法写在同1个模块之中
1.吃、喝、拉、撒、睡。。。基本行为
2.学习、敲代码、写书。。。学习
3.玩Dota、玩LOL、玩CF。。。玩
4.爬山、跑步、踢足球。。。运动
#import
@interface Student:NSObject
@property(nonatomic,strong)NSString *name;
@property(nonatomic,assign)int age;
@property(nonatomic,strong)NSString *stuNumber;
@end
#import “Student.h”
@implementation Student
@end
#import “Student.h”
@interface Student (basic)
– (void)eat;
– (void)drink;
– (void)la;
– (void)sa;
– (void)sleep;
@end
#import “Student+basic.h”
@implementation Student (basic)
– (void)eat{}
– (void)drink{}
– (void)la{}
– (void)sa{}
– (void)sleep{}
@end
#import “Student.h”
@interface Student (play)
– (void)playDota;
– (void)playLOL;
– (void)playCF;
@end
#import “Student+play.h”
@implementation Student (play)
– (void)playDota{}
– (void)playLOL{}
– (void)playCF{}
@end