zoukankan      html  css  js  c++  java
  • OC7_代理的基本概念

    //
    //  Cat.h
    //  OC7_代理的基本概念
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @interface Cat : NSObject
    
    - (void)bark;
    
    @end
    
    
    //
    //  Cat.m
    //  OC7_代理的基本概念
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "Cat.h"
    
    @implementation Cat
    
    - (void)bark
    {
        NSLog(@"Miao miao miao ...");
    }
    
    @end
    
    
    //
    //  Dog.h
    //  OC7_代理    的基本概念
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @interface Dog : NSObject
    
    - (void)bark;
    
    @end
    
    
    //
    //  Dog.m
    //  OC7_代理的基本概念
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "Dog.h"
    
    @implementation Dog
    
    - (void)bark
    {
        NSLog(@"Wang wang wang ...");
    }
    
    @end
    
    
    //
    //  Person.h
    //  OC7_代理的基本概念
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @interface Person : NSObject
    {
        id _delegate;
    }
    
    @property (retain,nonatomic)id delegate;
    
    - (void)go;
    
    
    @end
    
    
    //
    //  Person.m
    //  OC7_代理的基本概念
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "Person.h"
    #import "Dog.h"
    #import "Cat.h"
    
    @implementation Person
    
    - (void)go
    {
        [_delegate bark];
    }
    
    //- (void)dealloc
    //{
    //    [_delegate release];
    //    [super dealloc];
    //}
    
    @end
    //
    //  main.m
    //  OC7_代理的基本概念
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "Person.h"
    #import "Dog.h"
    #import "Cat.h"
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            // insert code here...
            //NSLog(@"Hello, World!");
            Person *xiaoXin = [[Person alloc] init];
            Dog *dog = [[Dog alloc] init];
            xiaoXin.delegate = dog;
            [xiaoXin go];
            Cat *cat = [[Cat alloc] init];
            xiaoXin.delegate =cat;
            [xiaoXin go];
        }
        return 0;
    }
  • 相关阅读:
    Nginx配置文件详解
    JVM调优—性能分析神器-JProfiler详解
    Navicat Premium 15破解
    Nginx配置反向代理,负载均衡,动静分离,高可用
    Nginx安装和常用命令
    Spring中ApplicationContextAware的作用
    java中发起http和https请求
    MySql高可用架构
    matlab画3维meshgrid/plot3/mesh/surf的用法
    如何规范地编写一个MATLAB函数文件
  • 原文地址:https://www.cnblogs.com/0515offer/p/4598549.html
Copyright © 2011-2022 走看看