• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Protocol implementation split between base and derived class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Protocol implementation split between base and derived class


  • Subject: Re: Protocol implementation split between base and derived class
  • From: Scott Hancher <email@hidden>
  • Date: Wed, 8 Dec 2004 15:15:07 -0800

You are correct. This would eliminate the compiler warning. However, I want to leverage the compiler to warn me when I haven't implemented all the protocol methods. Adding placeholder methods that throw an exception would quiet the warning but would hide a potential error that I would then have to uncover through more time consuming testing.

I would argue that my example Foo implements both of the FooProtocol methods that it proclaims to conform to. The fact that one of the two protocol methods is implemented on the base class it derives from is immaterial.

++Scott.

On Wednesday, December 8, 2004, at 02:48  PM, Ricky Sharp wrote:


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
  • Follow-Ups:
    • Re: Protocol implementation split between base and derived class
      • From: Christian Brunschen <email@hidden>
References: 
 >Re: Protocol implementation split between base and derived class (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: Protocol implementation split between base and derived class
  • Next by Date: Re: reversing an NSString
  • Previous by thread: Re: Protocol implementation split between base and derived class
  • Next by thread: Re: Protocol implementation split between base and derived class
  • Index(es):
    • Date
    • Thread