iOS与设计模式五:模版方法模式
2013-11-24 23:30
260 查看
多次出现,可重复使用的方法,可将其搬到父类中,子类就不必重复写这些代码,只需专心去实现差异性的代码。模版方法模式为代码提供了一个很好的复用平台。
@interface MySuperClass : NSObject
@property (retain,nonatomic) NSString *aPropertyString; //这个属性都具备
- (void)operationFirst;
- (void)operationSecond;
@end
@implementation MySuperClass
- (void)operationFirst
{
}
- (void)operationSecond
{
NSLog(@"这个方法是通用的");
}
@end
@interface ClassA : MySuperClass
- (void)operationFirst;
@end
@implementation ClassA
- (void)operationFirst
{
NSLog(@"ClassA我需要实现我自己的方法");
}
@end
@interface ClassB : MySuperClass
- (void)operationFirst;
@end
@implementation ClassB
- (void)operationFirst
{
NSLog(@"ClassB我需要实现我自己的方法");
}
@end
@interface MySuperClass : NSObject
@property (retain,nonatomic) NSString *aPropertyString; //这个属性都具备
- (void)operationFirst;
- (void)operationSecond;
@end
@implementation MySuperClass
- (void)operationFirst
{
}
- (void)operationSecond
{
NSLog(@"这个方法是通用的");
}
@end
@interface ClassA : MySuperClass
- (void)operationFirst;
@end
@implementation ClassA
- (void)operationFirst
{
NSLog(@"ClassA我需要实现我自己的方法");
}
@end
@interface ClassB : MySuperClass
- (void)operationFirst;
@end
@implementation ClassB
- (void)operationFirst
{
NSLog(@"ClassB我需要实现我自己的方法");
}
@end
相关文章推荐
- iOS 设计模式之模版方法模式 (TemplateMethod)
- GOF 23 设计模式 之 模版方法模式(template method)
- 设计模式-模版方法(行为型)
- 设计模式 - 模版方法模式 Template Method
- java设计模式(二):Template Method(模版方法)
- 设计模式之模版方法模式
- 方法模版模式(设计模式_11)【精品博客】
- 设计模式: 8. 模版方法模式(Template Method)
- 行为型:设计模式之模版方法模式(十七)
- 设计模式23篇:模版方法模式
- 23种设计模式之模版方法模式
- 设计模式-模版方法模式(8)
- iOS设计模式-工厂方法
- 设计模式--模版方法(TemplateMethod)
- 设计模式之——模版方法模式
- 模版方法设计模式
- 第十六篇 设计模式--模版方法模式
- 模版方法设计模式
- 设计模式之模版方法设计模式
- iOS设计模式:工厂方法