Re: Cocoa coding style (was Re: Did I reinvent the wheel?)
Re: Cocoa coding style (was Re: Did I reinvent the wheel?)
- Subject: Re: Cocoa coding style (was Re: Did I reinvent the wheel?)
- From: Chris Hanson <email@hidden>
- Date: Fri, 09 May 2008 22:43:49 -0700
On May 9, 2008, at 8:32 PM, Michael Watson wrote:
And do not override any of the following to implement singletons! -
allocWithZone: -copyWithZone: -retain -retainCount -release -
autorelease Instead, just add a "+sharedWhatever" class method.
<http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_10.html
>
I'll be filing a bug on that tonight.
In general terms though, I'll still state that it's a bad idea to
enforce that an object be a singleton — especially if you're new to
the framework and memory management rules etc.
Rather, I'd treat being a singleton as a code smell, and try to ask
whether methods on the singleton instance should be class methods, or
whether a "shared" singleton would be useful while leaving room for
specific instances in the future (and specific instances to use during
unit testing). For one thing, enforced singletons are hard to
subclass and substitute; being able to do so is quite useful in
certain circumstances.
Thanks for the reminder, though. I'm definitely going to be filing a
bug to adjust the documentation such that people used to other
frameworks don't just start automatically overriding -retain and -
release and so on because "that's how you do singleton classes in
Cocoa."
-- Chris
_______________________________________________
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