//创建买房协议
@protocol maiFangProtocol
-(void)maiFang;
@end
//创建代理类
#import<Foundation/Foundation.h>
#import"maiFangProtocol"
@interface LinkHome:NSObject(maiFangProtocol)
@end
#import"LinkHome.h"
@implementation LinkHome
-(void)maiFang{
NSLog(@"帮您找到房子");
}
@end
//创建顾客类
#import"maiFangProtocol.h"
@interface guKe:NSObject
@property id<maiFangProtocol> delegation;
-(void)needHouse;
@end
#import"guKe.h"
@implementation guKe
-(void)needHouse{
[self maiFang];
}
@end
//主函数
#import "guKe.h"
#import "LinkHouse.h"
int main(){
guKe *gk=[guKe new];
LinkHome *lh=[LinkHome new];
gk.delegation=lh;
[gk needHouse];
return 0;
} |
|