Re: Lack of Initializers or Factory Methods
Re: Lack of Initializers or Factory Methods
- Subject: Re: Lack of Initializers or Factory Methods
- From: "Michael Ash" <email@hidden>
- Date: Mon, 3 Nov 2008 11:37:46 -0500
On Mon, Nov 3, 2008 at 11:30 AM, Gordon Apple <email@hidden> wrote:
> Is "self" even defined for a class object? If so, should case 1 (or
> similar) be the assumed implementation for all of Cocoa? If not, then,
> IMHO, the docs in general should specify which is is for each factory
> method.
Yes, classes are objects too, and 'self' has the exact same meaning in
a class method as it does in an instance method. (That meaning is, it
is the receiver of the message.)
If the method is declared like this then you should assume that you
get a subclass:
+ (id)foo;
And if it is declared like this then you should not assume that:
+ (Foo *)foo;
The difference being the return type. The 'id' return type implicitly
means "this will return whatever is appropriate for the receiver".
(This should probably be documented better.) The 'Foo *' return type
tells you only to expect a Foo, and not rely on receiving any sort of
subclass.
The latter form is rare in Cocoa but shows up in e.g. NSParagraphStyle.
Mike
_______________________________________________
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