//
//  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;
}

 

相关文章:

  • 2021-08-04
  • 2021-09-26
  • 2021-10-31
  • 2021-08-27
  • 2021-07-16
  • 2021-10-13
  • 2021-09-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-11-29
  • 2021-12-30
相关资源
相似解决方案