Re: OOP Clarification
Re: OOP Clarification
- Subject: Re: OOP Clarification
- From: "John C. Randolph" <email@hidden>
- Date: Fri, 4 Jan 2002 15:36:33 -0800
On Friday, January 4, 2002, at 02:41 PM, Rick wrote:
>
>
Same applies to Obj-C...you don't have "self" and "super"
>
inside those class methods, so you can't override or access
>
parent class methods. But, just as shown above, you can have
>
the same class methods in multiple Obj-C classes.
No, self and super do exist in Obj-C class methods, and you can
indeed override inherited class methods.
@interface ParentClass : NSObject
+ myInit;
+ (void) mustImplementMe;
@end
@interface ChildClass : ParentClass
+ myInit;
+ (void) mustImplementMe;
@end
@implementation ParentClass
+ myInit
{
NSLog(@"initializing...");
return self;
}
+ (void) mustImplementMe
{
NSLog(@"This method must be implemented by subclasses! I quit!");
exit (0);
}
@end
@implementation ParentClass
+ myInit
{
[super myInit];
// do something else here..
NSLog(@"..and initializing some more");
return self;
}
+ (void) mustImplementMe
{
NSLog(@"We're still up, because I didn't call the inherited
+mustImplementMe method.");
}
@end
-jcr
"The problem with trying to child-proof the world, is that it
makes people neglect the far more important task of
world-proofing the child." -- Hugh Daniel