Re: Help on subclassing
Re: Help on subclassing
- Subject: Re: Help on subclassing
- From: Jon Adelman <email@hidden>
- Date: Wed, 30 Nov 2005 17:13:34 -0700
Declare a protocol for the methods that you are going to be using in
both B and C
@protocol myProtocol
- (NSRect) someMethod;
@end
Make A Subscribe to that protocol
@interface A : NSObject <myProtocol>
@end
On 30-Nov-05, at 4:09 PM, Joachim wrote:
Esteemed experts,
I'm working with 2 classes, B and C, that are quite similar to each
other. One of them is a preview of the other. They both inherit
from their superclass, A, that will never be instantiated (like an
abstract class). All functionality that is the same for both B and
C is of course placed in A, and the methods that differ are put in
the respective B and C subclasses.
From within the generic code (in the A class), I'd like to call
code that's declared and will be run in the respective B and C
subclasses. That is, from within A I'd like to call [self
someMethod], where someMethod only exists in B and C - not in A.
How do I do this?
In my attempts, the compiler warns that A may not respond to
someMethod which is fine, because I know it will at runtime. And it
works as expected at runtime. But if someMethod returns a value,
the compiler throws an error:
NSRect myRect = [self someMethod];
-> error: invalid initializer
(or
NSRect myRect;
myRect = [self someMethod];
-> error: incompatible types in assignment)
My workaround is to declare the method in A where I just return a
"dummy" value, because it's never used anyway. But it's not very
nice to look at and shouldn't be necessary. Any solution to this?
Thanks you for your help,
Joachim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40conversionworks.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