Dog类
- #import "Animal.h"
- #import "DogDelegate.h"
- //枚举
- typedef enum{
- HEALTH,SICK
- } Status;
- @interface Dog : Animal
- @property(nonatomic,assign) id<DogDelegate> delegate;
- @property(nonatomic,assign) Status status;
- //狗狗生病
- -(void)dogSick;
- @end
复制代码
Dog实现类
- #import "Dog.h"
- @implementation Dog
- #pragma mark - 重写status的set方法
- -(void)setStatus:(Status)status{
- _status = status;
- if (_status == SICK) {
- [self dogSick];
- }
- }
- -(void)dogSick{
- NSLog(@"狗狗生病了");
- [self cureDog];
- }
- -(void)cureDog{
- [self.delegate cureDog];
- }
- @end
复制代码
协议类
- @protocol DogDelegate <NSObject>
- -(void)cureDog;
- @end
复制代码 |