Re: Proper way to create a singleton without @synchronized ?
Re: Proper way to create a singleton without @synchronized ?
- Subject: Re: Proper way to create a singleton without @synchronized ?
- From: Greg Parker <email@hidden>
- Date: Sun, 17 Apr 2011 23:07:32 -0700
On Apr 17, 2011, at 11:52 AM, Joanna Carter wrote:
> Tell me; maybe it's my background in other languages, but I would tend to use a "static class" as a singleton; or, at least, design a class with only class methods/properties, with static "fields" declared in the @implementation section of a class.
>
> Why this fascination with going to all the trouble of creating a singleton rather than using the "static class" approach?
A narrow technical reason: Objective-C's type system is limited when it comes to class objects. Singleton instances are better supported.
A software lifecycle reason: Sometimes an app evolves such that a task that used to be performed globally now needs to have multiple different local contexts. (Perhaps you wrote a single-window app with a singleton window controller, and now you want a multiple-window app.) Code written for a singleton instance can often be transformed to work with multiple instances. Code written for a static class may need more rewriting to handle the change.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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