Re: OOP Clarification
Re: OOP Clarification
- Subject: Re: OOP Clarification
- From: Marco Scheurer <email@hidden>
- Date: Fri, 4 Jan 2002 17:25:39 +0100
On Friday, January 4, 2002, at 04:40 pm, Smith, Bradley wrote:
Well, it does have a 'this' in the sense that it can access other static
variables and methods.
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.
When you say you can't overload static methods I'm not sure what you
mean.
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
I'm not trying to get into an argument here, it's just that I'm new to
Obj-C
and in my head I had class members in Obj-C as analagous to static
members
in C++. Would someone care to point out the differences, and I mean the
differences in how one can be used in a way that the other cannot.
For sure they can be used in analogous roles. Just as static variables
are sometimes used as a poor man's replacement for the lack of class
variables in Objective C, but there not exactly the same.
Other things that you cannot do with them are, of course, the runtime
things that you can do with all methods in Objective C (including class
methods) that you cannot do with any function.
marco
Marco Scheurer
Sen:te, Lausanne, Switzerland
http://www.sente.ch