RE: Convenience Methods
RE: Convenience Methods
- Subject: RE: Convenience Methods
- From: Jeff Laing <email@hidden>
- Date: Wed, 26 Sep 2007 11:46:17 +1000
> > 1) I've added a convenience method to a class of mine so that it
> > minimizes the init/retains needed to create one just to slap into
> > an array. My question is, in the method should I be returning an
> > object of type (id) or an object that is the type of the class I'm
> > returning?
>
> You should always return an object of type id, so that the class
> method will work correctly with subclasses of the object.
Sorry, I don't understand this.
There is no way the class method is going to return subclasses.
If you mean, so you can overload the class method in subclasses, then they
can still return the superclass since anything they create will be valid
instance of the superclass. They'll be a valid instance of the subclass as
well.
(Typically, you wouldn't implement the same named convenience in a subclass
anyway - the name of the convenience is typically derived from the class it
is returning/is a part of)
Personally, I think too much use of 'id' subverts the compilers natural
ability to detect missing method definitions, etc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden