@fiy-fish
2015-07-18T19:44:15.000000Z
字数 1380
阅读 1288
Objective-c
#import <Foundation/Foundation.h>
#import "MyButton.h"
#import "MyButton_a.h"
#import "MyButton_b.h"
#import "MyButton_AA.h"
#import "MyButton_BB.h"
//创建四个按钮分别是 a A b B
//输入a A b B 其中一种, 让对应的按钮输出 轻拳 重拳 轻腿 重腿
int main(int argc, const char * argv[]) {
@autoreleasepool {
//MyButton *btn = [[MyButton alloc] init];
MyButton_a *a = [[MyButton_a alloc] init];
MyButton_AA *A = [[MyButton_AA alloc] init];
MyButton_b *b = [[MyButton_b alloc] init];
MyButton_BB *B = [[MyButton_BB alloc] init];
NSDictionary *dic = @{@"a":a,@"A":A,@"b":b,@"B":B};
while(1)
{
char s[10] = {};
scanf("%s",s);
MyButton *btn = dic[[NSString stringWithUTF8String:s]];
[btn btnClick];
}
}
return 0;
}
#import "MyButton.h"
@interface MyButton_AA : MyButton
@end
#import "MyButton_AA.h"
@implementation MyButton_AA
-(void)btnClick
{
NSLog(@"重拳");
}
@end
#import "MyButton.h"
@interface MyButton_b : MyButton
@end
#import "MyButton_b.h"
@implementation MyButton_b
-(void)btnClick
{
NSLog(@"轻腿");
}
@end
#import "MyButton.h"
@interface MyButton_BB : MyButton
@end
#import "MyButton_BB.h"
@implementation MyButton_BB
-(void)btnClick
{
NSLog(@"重腿");
}
@end
#import "MyButton.h"
@interface MyButton_a : MyButton
@end
#import "MyButton_a.h"
@implementation MyButton_a
-(void)btnClick
{
NSLog(@"轻拳");
}
@end
#import <Foundation/Foundation.h>
@interface MyButton : NSObject
{
NSString *_name;
}
-(void)btnClick;
@end
#import "MyButton.h"
@implementation MyButton
-(instancetype)init
{
if(self = [super init])
{
_name = @"a";
}
return self;
}
-(void)btnClick
{
NSLog(@"被点击");
}
@end