• 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: Automagic instantiation of singletons? (Christian Brunschen)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automagic instantiation of singletons? (Christian Brunschen)


  • Subject: Re: Automagic instantiation of singletons? (Christian Brunschen)
  • From: Chris Hanson <email@hidden>
  • Date: Wed, 23 Nov 2005 00:23:16 -0800

On Nov 22, 2005, at 11:14 PM, Greg Herlihy wrote:

As already noted, it is possible to implement a similar model in Objective C
by defining a class method that returns the Singleton object, instantiating
it if necessary. Provided that other dependent singletons follow this model,
there should be no order-of-construction problems. And in fact some
Foundation objects already follow this approach: NSApplication's
sharedApplication is one example.

The above is the pattern I would suggest for implementing singletons in Objective-C.


I would further suggest that developers should generally not go out of their way to ensure that a singleton is "truly" a singleton, by overriding -retain, -release, -autorelease, -init, etc. Being able to directly instantiate objects of a class -- even if doing so isn't part of the class's API contract -- makes it much easier to write effective unit tests involving that class.

  -- Chris

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Automagic instantiation of singletons? (Christian Brunschen) (From: Greg Herlihy <email@hidden>)

  • Prev by Date: Re: Automagic instantiation of singletons?
  • Next by Date: fileURL - retrieving from NSDocument
  • Previous by thread: Re: Automagic instantiation of singletons? (Christian Brunschen)
  • Next by thread: Re: Automagic instantiation of singletons? (Christian Brunschen)
  • Index(es):
    • Date
    • Thread