Re: Protocol implementation split between base and derived class
Re: Protocol implementation split between base and derived class
- Subject: Re: Protocol implementation split between base and derived class
- From: Ricky Sharp <email@hidden>
- Date: Wed, 8 Dec 2004 16:48:03 -0600
On Dec 8, 2004, at 4:35 PM, Scott Hancher wrote:
I've defined a protocol. I have several classes that need to implement
this protocol. A subset of the protocol methods have general
implementations that can be implemented in a common super class.
However, XCode doesn't appear to accept the super class's
implementation in determining whether each derived class implements
the entire protocol.
I can get around this by adding an implementation of each of the super
class methods in each subclass and calling the corresponding super
method. This step doesn't seem like it should be necessary though.
Is there any other way around this? Is this a bug in XCode?
I've included a simple example of the problem I've described along
with the corresponding XCode warnings.
++Scott.
@protocol FooProtocol
- (void)Foo1;
- (void)Foo2;
@end
@interface BaseFoo
- (void)Foo1;
@end
What if you did this:
@interface BaseFoo : NSObject <FooProtocol>
- (void)Foo1;
- (void)Foo2;
@end
Your implementation of Foo2 can simply do nothing (or perhaps raise an
exception to alert you to the fact that a derived class must implement
it).
@interface Foo : BaseFoo <FooProtocol>
- (void)Foo2;
@end
This can then be:
@interface Foo: BaseFoo
- (void)Foo2;
@end
This should allow both your objects to conform to FooProtocol; yet the
implementation is ultimately split amongst the two.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden