RE: OOP Clarification
RE: OOP Clarification
- Subject: RE: OOP Clarification
- From: "Smith, Bradley" <email@hidden>
- Date: Fri, 4 Jan 2002 17:36:02 -0000
See comments:
>
-----Original Message-----
>
From: Marco Scheurer [mailto:email@hidden]
>
Sent: 04 January 2002 16:26
>
>
In Foundation's NSObject:
>
>
+ (id) alloc
>
{
>
return [self allocWithZone:nil];
>
}
>
>
>
+ (id) allocWithZone:(NSZone *) aZone
>
{
>
// ...;
>
}
>
>
If you override +allocWithZone in the Foo subclass of NSObject, [Foo
>
alloc] will use Foo's allocWithZone implementation. Does it
>
work like so
>
in C++? I maybe mistaken (my C++ is rusty... ), but I think not.
Nope. Doesn't work. It'll call the one in the base class.
>
I meant overriding. Can you redefine a static method in a
>
subclass and
>
invoke the base class implementation?
>
>
@implementation Animal
>
+ (void) doSomething
>
{
>
//...
>
}
>
@end
>
>
@implementation Tiger : Animal
>
+ (void) doSomething
>
{
>
//...
>
[super doSomething];
>
}
>
@end
>
Yes. Not as elegantly though 'cos you can't refer to the superclass in C++
without knowing what it is. So, class bar derives from foo then the method
on bar has to call foo::theMethod rather than super::theMethod.
Anyway, I see the differences now. Thanks to everyone who helped clear that
up.
Brad