FROM : Gregory Weston
DATE : Fri Feb 15 22:55:18 2008
Keith Duncan wrote:
>> As far as I understand, [Foo new] is exactly equivalent to [[Foo
>> alloc] init]
>
> Correct.
Incorrect. Based on the documentation new (by default) does setup
work analogous to alloc and then invokes init before returning the
object. It does not actually use the alloc method, though, which
means it's entirely possible for new to not be equivalent to an alloc/
init pair.
> Chaining alloc and init is just the in vogue convention as far as I
> know. I've been told that -new used to be a popular way of doing it
> back in the days of NeXTStep.
It's more than just the 'in vogue convention' though. The point was
to recognize that allocation and initialization are distinct actions
and there's benefit in having them be separable. With alloc/init you
can change one of the phases without concern for the other.
DATE : Fri Feb 15 22:55:18 2008
Keith Duncan wrote:
>> As far as I understand, [Foo new] is exactly equivalent to [[Foo
>> alloc] init]
>
> Correct.
Incorrect. Based on the documentation new (by default) does setup
work analogous to alloc and then invokes init before returning the
object. It does not actually use the alloc method, though, which
means it's entirely possible for new to not be equivalent to an alloc/
init pair.
> Chaining alloc and init is just the in vogue convention as far as I
> know. I've been told that -new used to be a popular way of doing it
> back in the days of NeXTStep.
It's more than just the 'in vogue convention' though. The point was
to recognize that allocation and initialization are distinct actions
and there's benefit in having them be separable. With alloc/init you
can change one of the phases without concern for the other.






Cocoa mail archive

