您的位置:首页 > 移动开发 > IOS开发

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





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 设计模式