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;
    }
  • 相关阅读:
    spring 解析bean
    Spring Cloud
    Spring
    JDK动态代理源码实现深入分析
    一个很坑的问题,button 的onclick方法失效了
    web总结
    字符串编码
    海量数据的解决方案--笔记
    链接保存
    读《JVM虚拟机》- 集中简单的垃圾收集算法
  • 原文地址:https://www.cnblogs.com/0515offer/p/4598549.html
Copyright © 2011-2022 走看看