zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    wifi与wimax
    短信中心号码
    (安卓)黑盒测试技巧个人整理
    数组实现栈的结构(java)
    tikv性能参数调优
    pt-table-checksum工具MySQL主从复制数据一致性
    MySQL索引原理以及类型
    TiDB数据库 mydumper与loader导入数据
    Innodb的体系结构
    MySQL核心之双一原则
  • 原文地址:https://www.cnblogs.com/0515offer/p/4598507.html
Copyright © 2011-2022 走看看