OC4_遵守多个协议

//
//  Calulator.h
//  OC4_遵守多个协议
//
//  Created by zhangxueming on 15/6/24.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Adder.h"
#import "Subber.h"
#import "Multter.h"
#import "Divver.h"

//遵守多个协议, 协议之间用逗号隔开
@interface Calulator : NSObject <Adder,Subber,Multter,Divver>

@end


//
//  Calulator.m
//  OC4_遵守多个协议
//
//  Created by zhangxueming on 15/6/24.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import "Calulator.h"

@implementation Calulator

+ (int)addA:(int)a andB:(int)b
{
    return a+b;
}

+ (int)subA:(int)a andB:(int)b
{
    return a-b;
}

+ (int)divA:(int)a andB:(int)b
{
    return a/b;
}

+ (int)mulA:(int)a andB:(int)b
{
    return a*b;
}

@end
//
//  Divver.h
//  OC4_遵守多个协议
//
//  Created by zhangxueming on 15/6/24.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol Divver <NSObject>

+ (int)divA:(int)a andB:(int)b;

@end


//
//  Multter.h
//  OC4_遵守多个协议
//
//  Created by zhangxueming on 15/6/24.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol Multter <NSObject>

+ (int)mulA:(int)a andB:(int)b;

@end


//
//  Subber.h
//  OC4_遵守多个协议
//
//  Created by zhangxueming on 15/6/24.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol Subber <NSObject>

+ (int)subA:(int)a andB:(int)b;

@end


//
//  Adder.h
//  OC4_遵守多个协议
//
//  Created by zhangxueming on 15/6/24.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol Adder <NSObject>

+ (int)addA:(int)a andB:(int)b;

@end
//
//  main.m
//  OC4_遵守多个协议
//
//  Created by zhangxueming on 15/6/24.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Calulator.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSLog(@"add = %i", [Calulator addA:3 andB:5]);
        NSLog(@"mul = %i", [Calulator mulA:5 andB:10]);
    }
    return 0;
}

 

posted @ 2015-06-24 19:43  sirzhang  阅读(449)  评论(0编辑  收藏  举报
AmazingCounters.com