Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Foo new] vs [[Foo alloc] init]:




On Feb 17, 2008, at 3:06 PM, Bill Bumgarner wrote:

On Feb 17, 2008, at 11:15 AM, Gregory Weston wrote:
See what you're saying? +alloc *or* +allocWithZone:.

See the subject? +alloc. It does not say anything about +allocWithZone:.

See this code?

@interface MyTest : NSObject
@end

@implementation MyTest
+ (id)alloc
{
 NSLog(@"allocating");
 return [super alloc];
}
@end

You would have to override +allocWithZone: to have any kind of reliable behavior.

Or you could just not assume that something which hasn't been explicitly stated in the docs is guaranteed. That's what I've been trying to say: The only promise the documentation makes about new, alloc and allocWithZone is that they're peers. It doesn't say a peep about any of them invoking any of the others to achieve that equivalence. That lack of explicit promise - the utter inability to make such a promise in general - is why it's wrong to say without a whole lot of caveats that one technique is precisely equivalent to another. Looking at the implementation of a method, rather than the interface, as it exists today and saying "you can count on this" is an outright rejection of one of the core concepts of OO.


+alloc is a cover for +allocWithZone: with a NULL zone. Not that you would know that from the documentation, unfortunately.

Which means, like the current behavior of new, that's an implementation detail that shouldn't really be relied on.


Without assuming anything, you would have to override both allocator methods; +alloc and +allocWithZone:.

So what you're saying is that [Foo new] isn't actually reliably equivalent to [[Foo alloc] init]? That all we can really assume about the default implementation of +new is that it performs behavior functionally equivalent to that performed by the default +alloc (and then invokes init)?
_______________________________________________


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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.