Re: [Foo new] vs [[Foo alloc] init]:
Re: [Foo new] vs [[Foo alloc] init]:
- Subject: Re: [Foo new] vs [[Foo alloc] init]:
- From: Alastair Houghton <email@hidden>
- Date: Mon, 18 Feb 2008 13:58:37 +0000
On 18 Feb 2008, at 13:11, Gregory Weston wrote:
You might think of +allocWithZone: as being the "designated
allocator"
(pre-Leopard, at least) -- you would always override that rather than
+alloc.
You might think of it that way, but you'd have no formal reason to
do so. The fact that alloc invokes allocWithZone: or that new
invokes either of them is an implementation detail not exposed
anywhere in the documentation or interface.
IMO it would be better if +alloc was explicitly documented to call
+allocWithZone:, and if people were told to override the latter method
in preference to the former (just filed as <rdar://5749202>). But I
think a lot of us always assumed that things worked that way (and that
we should override +allocWithZone:, not +alloc) because it's the same
pattern as for -copy/-copyWithZone: and -mutableCopy/-
mutableCopyWithZone:.
Relying on unpromised implementation details
I think the fact that this particular detail isn't documented is an
oversight, rather than a conscious decision. I think that's what Bill
has been trying to tell you. It probably *should* be documented,
which is why I just filed a bug report.
Likewise, it seems that the fact that +new *wasn't* calling +alloc is
arguably a bug (albeit a minor one), but since +allocWithZone:NULL
should always have been equivalent to +alloc, overriding just +alloc
would have been wrong in any case.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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