I have the following classes/protocols:
@interface Super
@end
@implementation Super
@end
@interface Sub1
@end
@implementation Sub1
@end
@interface Sub2
@end
@implementation Sub2
@end
@protocol FooProtocol
- (void) foo;
@end
@interface Sub1 (FooCategory) <FooProtocol>
@end
@implementation Sub1 (FooCategory)
- (void) foo {}
@end
@interface Sub2 (FooCategory) <FooProtocol>
@end
@implementation Sub2 (FooCategory)
- (void) foo {}
@end
@interface Super (FooCategory) <FooProtocol>
@end
// Notice that there is no @implementation Super (FooCategory)
This allows me to write a function similar to this:
void callFoo(NSArray *supers) {
for (Super *theSuper in supers) {
[theSuper foo];
}
}
Sub1
and Sub2
are Super
's only two subclasses. I essentially want polymorphism in a category method. If I specify an @interface
for Super
, but provide no @implementation
, clang doesn't give me any warnings/errors.
Is this a really bad hack?
What are the potential downsides?