【发布时间】:2010-05-18 04:13:12
【问题描述】:
我创建了一个我的类需要实现的协议,然后将一些常用功能分解到一个基类中,所以我这样做了:
@protocol MyProtocol
- (void) foo;
- (void) bar;
@end
@interface Base <MyProtocol>
@end
@interface Derived_1 : Base
@end
@interface Derived_2 : Base
@end
@implementation Base
- (void) foo{
//something foo
}
@end
@implementation Derived_1
- (void) bar{
//something bar 1
}
@end
@implementation Derived_2
- (void) bar{
//something bar 2
}
@end
这样,在我的代码中,我使用了一个通用的 id
代码有效(只要不直接使用 Base),但编译器在 Base 实现结束时会出现警告:
Base类实现不完整
有没有办法避免这个警告,或者更好的方法来获得 Objc 中这种部分实现的抽象基类行为?
【问题讨论】:
标签: objective-c oop coding-style