Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Categories overriding methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Categories overriding methods



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.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.