码迷,mamicode.com
首页 > 其他好文 > 详细

协议的应用-代理模式

时间:2015-02-28 21:31:50      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

//

//  main.m

//  07-协议的应用-代理模式

//

//  Created by apple on 13-6-30.

//  Copyright (c) 2013年 apple. All rights reserved.

//

 

#import <Foundation/Foundation.h>

#import "Person.h"

#import "Agent.h"

#import "NextAgent.h"

 

int main(int argc, const char * argv[])

{

 

    @autoreleasepool {

        Person *p = [[[Person alloc] init] autorelease];

        

        NextAgent *a = [[[NextAgent alloc] init] autorelease];

        

        p.delegate = a;

        

        [p buyTicket];

    }

    return 0;

}

 

void test()

{

    // 人

    Person *p = [[Person alloc] init];

    // 代理

    Agent *a = [[Agent alloc] init];

    

    // 设置人的代理

    p.delegate = a;

    

    // 人打算看电影

    [p buyTicket];

    

    [a release];

    [p release];

}

 

协议的应用-代理模式

标签:

原文地址:http://www.cnblogs.com/dahongliang/p/4306199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!