#import <Foundation/Foundation.h>
enum{GOODMAN,BADMAN} MAN;
@interface Animal : NSObject
{
int _legCount;
int _eyeCount;
}
-(void)setLegCount:(int)legCount;
-(int)getLegCount;
-(void)setEyeCount:(int)eyeCount;
-(int)getEyeCount;
-(void)run;
-(void)eat;
@end
@implementation Animal
-(void)setLegCount:(int)legCount{
_legCount = legCount;
}
-(int)getLegCount{
return _legCount;
}
-(void)setEyeCount:(int)eyeCount{
_eyeCount = eyeCount;
}
-(int)getEyeCount{
return _eyeCount;
}
-(void)run{
NSLog(@"runing...");
}
-(void)eat{
NSLog(@"eating...");
}
@end
@interface Dog : Animal
-(void)watchHouse;
-(void)biteMan;
@end
@implementation Dog
-(void)watchHouse{
switch (MAN) {
case GOODMAN:
NSLog(@"Watching House...");
break;
case BADMAN:
[self biteMan];
break;
default:
break;
}
}
-(void)biteMan{
NSLog(@"Bite a man...");
}
@end
@interface Cat : Animal
-(void)climbTree;
@end
@implementation Cat
-(void)climbTree{
[self eat];
NSLog(@"Climbing Tree...");
}
@end
int main(){
Dog *d = [Dog new];
Cat *c = [Cat new];
MAN=BADMAN;
[d watchHouse];
[c climbTree];
} |
|