Re: ARC and Singletons
Re: ARC and Singletons
- Subject: Re: ARC and Singletons
- From: Kyle Sluder <email@hidden>
- Date: Mon, 01 Aug 2011 21:02:31 -0700
On Mon, Aug 1, 2011 at 7:14 PM, Karl Goiser <email@hidden> wrote:
> Wow, class methods finally get the tick of approval! Only 30+ years after being specified in the Smalltalk standard..
>
>
> Forget about singletons: they are just a workaround for not having class methods/variables.
No, they're not. I mentioned the NSFileManager example above; that was
a great example of how the singleton pattern is more flexible than
using class methods for the same task.
Class methods have their purpose. Cocoa and Cocoa Touch use them to
great effect in places like +[UIView setAnimationsEnabled:], where the
method logically applies to instances of that class. They help
maintain encapsulation, since they are defined inside the class and
therefore, following typical good design principles, are allowed to
peek behind the public veil of instances.
But class methods aren't a replacement for the singleton pattern. Even
if we had class storage (which in practice would be no different from
static global variables except for scope), class methods would still
be appropriate for a different set of tasks.
I wouldn't hold my breath waiting for Apple or anyone else to drop the
singleton pattern and adopt class methods.
--Kyle Sluder
_______________________________________________
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