On Nov 3, 2008, at 8:37 AM, Michael Ash wrote:

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.


My understanding is that that this is the general pattern to use:

* Return (id) from initializers, and convenience factory methods.
* Return (Foo*) for shared instances.

There are some exceptions to these "rules" in Cocoa, but they are few and far in between. Note that "+[NSParagraphStyle defaultParagraphStyle]" fits this pattern, since it returns a shared instance.

j o a r


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to