Re: OOP Clarification
Re: OOP Clarification
- Subject: Re: OOP Clarification
- From: Greg Titus <email@hidden>
- Date: Fri, 4 Jan 2002 15:19:22 -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.
Um... no. You do have self and super in class methods, and you can
easily override and access parent class methods because classes are
first-class ("real") objects. They are normal methods in every respect
except that "self" is a Class object.
@interface A
+ foo;
@end
@interface B:A
+foo;
-bar;
@end
@implementation B
+ foo
{
[super foo]; // calls A's +foo
[self name]; // returns "B" -- self is a Class object
[[self alloc] init]; // is the same as [[B alloc] init]
}
- bar
{
[[self class] foo]; // calls B's foo. The method is overridden...
}
@end
Hope this helps,
--Greg