• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Categories overriding methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Categories overriding methods
      • From: Ondra Cada <email@hidden>
    • Re: Categories overriding methods
      • From: "John C. Randolph" <email@hidden>
    • Re: Categories overriding methods
      • From: "John C. Randolph" <email@hidden>
  • Prev by Date: Re: Resizing NSSplitView
  • Next by Date: Re: networking...
  • Previous by thread: Re: Missing Class in nib.
  • Next by thread: Re: Categories overriding methods
  • Index(es):
    • Date
    • Thread