Categories overriding methods
Categories overriding methods
- Subject: Categories overriding methods
- From: David Newberry <email@hidden>
- Date: Thu, 1 Aug 2002 21:06:54 -0700
Hello all,
I am thinking about using a category to over-ride a class's init: method
to return a subclass of that class. (Make sense? :) My question is
basically, is that OK? I'm getting a mixed impression from the docs:
"It's best if categories don't attempt to redefine methods that are
explicitly declared in the class's @interface section. ...
Note: When a category overrides an inherited method, the new version
can, as usual, incorporate the inherited version through a message to
super. But there's no way for a category method to incorporate a method
with the same name defined for the same class."
I read that and basically... I don't get it. This is what I'm thinking of
trying to do...
In my category (of MyClass):
- (id)initWithInfo:(id)info
{
[self autorelease];
return [[MySubclass alloc] initWithInfo:info];
}
In MySubclass:
- (id)initWithInfo:(id)info
{
return [super initWithInfo:info]; // calls MyClass' initWithInfo:
}
Is this... reasonable code? The reason I want to do this is because I want
code that's already wired to create instances of MyClass to instead create
instances of MySubclass without fiddling with the existing code.
Thanks,
-David Newberry
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.