• 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
Re: Lack of Initializers or Factory Methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Lack of Initializers or Factory Methods
      • From: j o a r <email@hidden>
References: 
 >Re: Lack of Initializers or Factory Methods (From: Gordon Apple <email@hidden>)

  • Prev by Date: Re: Modal Dialog Issue
  • Next by Date: Re: Lack of Initializers or Factory Methods
  • Previous by thread: Re: Lack of Initializers or Factory Methods
  • Next by thread: Re: Lack of Initializers or Factory Methods
  • Index(es):
    • Date
    • Thread