////ProtectedDelegate.h//Basic concept of oc8_ agent////Created by zhangxueming on 15/6/24.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import<Foundation/Foundation.h>@protocolProtecteddelegate <nsobject>-(void) bark;@end////Person.h//Basic concept of oc8_ agent////Created by zhangxueming on 15/6/24.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import<Foundation/Foundation.h>#import "ProtectedDelegate.h"@interfaceperson:nsobject{ID<ProtectedDelegate>_delegate;}//object pointers are also subject to protocol@property (Retain, nonatomic)ID<ProtectedDelegate>Delegate;- (void) go;@end////person.m//Basic concept of oc8_ agent////Created by zhangxueming on 15/6/24.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import "Person.h"@implementation Person- (void) go{[_delegate bark];}@end////Cat.h//Basic concept of oc8_ agent////Created by zhangxueming on 15/6/24.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import<Foundation/Foundation.h>#import "ProtectedDelegate.h"//Include header file@interfaceCat:nsobject <protecteddelegate>//abide by this Agreement@end////CAT.M//Basic concept of oc8_ agent////Created by zhangxueming on 15/6/24.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import "Cat.h"@implementationCat- (void) bark{NSLog (@"Miao Miao Miao ...");}@end////Dog.h//Basic concept of oc8_ agent////Created by zhangxueming on 15/6/24.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import<Foundation/Foundation.h>#import "ProtectedDelegate.h"@interfaceDog:nsobject <ProtectedDelegate>@end////DOG.M//Basic concept of oc8_ agent////Created by zhangxueming on 15/6/24.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import "Dog.h"@implementationDog- (void) bark{NSLog (@" Wang Wang Wang ...");}@end////main.m//Basic concept of oc8_ agent////Created by zhangxueming on 15/6/24.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import<Foundation/Foundation.h>#import "Dog.h"#import "Cat.h"#import "Person.h"intMainintargcConst Char*argv[]) {@autoreleasepool { 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;}
Basic concept of oc8_ Agent