Re: [Foo new] vs [[Foo alloc] init]:
Re: [Foo new] vs [[Foo alloc] init]:
- Subject: Re: [Foo new] vs [[Foo alloc] init]:
- From: Bill Bumgarner <email@hidden>
- Date: Fri, 15 Feb 2008 15:39:40 -0800
On Feb 15, 2008, at 3:26 PM, Hamish Allan wrote:
On Feb 15, 2008 11:11 PM, Bill Bumgarner <email@hidden> wrote:
On Leopard, +new is implemented as return [[self alloc] init]; It
is
equivalent unless a subclass overrides, which is exceedingly
unlikely.
And, I would have thought, exceedingly rash. What would be gained by
implementing a non-equivalent behaviour that would outweigh the
potential for confusion and error?
Taking a relatively simple problem and making it mentally challenging
enough to hold the attention of a talented software engineer?
Seriously -- I can't really think of any reason to override +new to do
something goofy that isn't, otherwise, an *exact* cover for +alloc/-
init of the same class.
That is, if you need custom allocation behavior, override +alloc. If
you need custom initialization, override -init.
If you need both, override +alloc and -init ... +new will "just work".
The documentation is actually a little confusing on this one. It
implies that +new is sometimes re-implemented in subclasses in the
initial sentence on the topic, but the rest of the write-up is how it
is actually implemented as +new... where the "..." implies "with a set
of arguments that provide custom initialization".
b.bum
_______________________________________________
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