#import"Decorator.h"
复制代码@implementation Decorator
-(void)SetComponents:(Components*)component{
components = component;
}
-(void)Operation{
if(components!=nil){
[components Operation];
}
}
@end
ConcreteComponent类接口文件
复制代码
#import"Components.h"
@interface ConcreteComponent :Components
@end
ConcreteComponent类实现文件
复制代码
#import "ConcreteComponent.h"
@implementation ConcreteComponent
-(void)Operation{
NSLog(@"具体操作的对象");
}
@end
ConcreteDecoratorA类接口文件
复制代码
#import "ConcreteDecoratorA.h"
#import "Decorator.h"
@interface ConcreteDecoratorA :Decorator
@end
ConcreteDecoratorA类实现文件
#import"ConcreteDecoratorA.h"
复制代码@implementation ConcreteDecoratorA
-(void)Operation{
NSLog(@"具体装饰对象A的操作");
[super Operation];
}
@end
ConcreteDecoratorB类接口文件
#import "Decorator.h"
复制代码@interface ConcreteDecoratorB :Decorator
@end
ConcreteDecoratorB类实现文件
复制代码
#import "ConcreteDecoratorB.h"
@implementation ConcreteDecoratorB
-(void)Operation{
NSLog(@"具体装饰对象B的操作");
[super Operation];
}
@end
Main方法
复制代码
#import <Foundation/Foundation.h>
#import "ConcreteComponent.h"
#import "ConcreteDecoratorA.h"
#import "ConcreteDecoratorB.h"
int main (int argc,const char* argv[])










