我已经创建了我的课需要实现一个协议,然后分解出一些常见的功能集成到一个基类部分基类“完全执行”警告,所以我这样做:如何避免
@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
在我的代码中以这种方式使用通用编号<MyProtocol>。
代码工作(只要基本不能直接使用),但编译器扼流圈在基地实施的最后一个警告:
Incomplete implementation of class Base
是否有办法避免这种警告,或甚至更好,在Objc中获得这种部分实现的抽象基类行为的更正确方法?
好吧,这将至少强制执行大多数派生类中的实现。 虽然编译时间警告对于未实现的方法会很好,但是我想没有办法(?) 有没有一种正确的方法可以在Obj-c中完成这个基类的部分实现? – garph0 2010-05-18 10:41:20
不是。正如其他人所指出的,Objective-C没有抽象基类。我用过的每种方法都只能让你分开。 – mipadi 2010-05-18 12:03:36