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

代理模式

时间:2015-03-16 00:49:10      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

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

    Person *person = [[Person alloc]init];
    
    Ticker *ticker = [[Ticker alloc]init];
    
    person.delegate=ticker;
    
    [person buyTicker];

    return 0;
}

Person.h
@interface Person : NSObject

@property (nonatomic, strong) id<TickerDelegate> delegate;

-(void)buyTicker;

@end

Person.m
@implementation Person
-(void)buyTicker
{
    int num = [_delegate getTickerNumber];
    double price = [_delegate getTickePrcie];
    NSLog(@"%d, %f", num, price);
}
@end

Ticker.h
@interface Ticker : NSObject<TickerDelegate>
@end

Ticker.m
@implementation Ticker
-(double)getTickePrcie
{
    return 50;
}

-(int)getTickerNumber
{
    return 10;
}
@end

TickerDelegate.h
@protocol TickerDelegate <NSObject>
-(int)getTickerNumber;
-(double)getTickePrcie;
@end

 

代理模式

标签:

原文地址:http://www.cnblogs.com/jsnan/p/4340849.html

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