• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Proper way to create a singleton without @synchronized ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Proper way to create a singleton without @synchronized ?
      • From: Joanna Carter <email@hidden>
References: 
 >Proper way to create a singleton without @synchronized ? (From: WT <email@hidden>)
 >Re: Proper way to create a singleton without @synchronized ? (From: Kyle Sluder <email@hidden>)
 >Re: Proper way to create a singleton without @synchronized ? (From: WT <email@hidden>)
 >Re: Proper way to create a singleton without @synchronized ? (From: Dave DeLong <email@hidden>)
 >Re: Proper way to create a singleton without @synchronized ? (From: WT <email@hidden>)
 >Re: Proper way to create a singleton without @synchronized ? (From: Joanna Carter <email@hidden>)

  • Prev by Date: Re: Proper way to create a singleton without @synchronized ?
  • Next by Date: Re: renaming directories and moving files into them (NSFileManager)
  • Previous by thread: Re: Proper way to create a singleton without @synchronized ?
  • Next by thread: Re: Proper way to create a singleton without @synchronized ?
  • Index(es):
    • Date
    • Thread