• 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: Is Apple's singleton sample code correct?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is Apple's singleton sample code correct?


  • Subject: Re: Is Apple's singleton sample code correct?
  • From: Ondra Cada <email@hidden>
  • Date: Fri, 2 Dec 2005 11:00:01 +0100

Mmalc,

On 2.12.2005, at 5:25, mmalcolm crawford wrote:

Attempting to copy a singleton should really result in an error

Far as we are speaking generally, I beg to differ: again, it is quite conceivable you may need to use the singleton in another code, which merrily copies, and which is not to be changed just since it is about to use the singleton now, instead whatever else it has been originally written to work with: reusability/polymorphism.

Agreeably there are singletons which should not be copiable. On the other hand, consider [NSNull null], which is about to be copied all the time :)

Myself, I would consider it a general rule (certainly not without exceptions!) that

(a) either the singleton is to be used *exclusively* through a singleton interface (read in +sharedInstance or similar, NSUserDefaults a prime example), and then there is hardly a need to override anything (if at all, then for defensive purposes only, to guard from client code errors, like overreleasing).

(b) or the singleton is intended to be used amongst normal instances (NSNull a prime example). In that case, about all the memory- management code *is* to be overridden, incl. copyWithZone.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc


_______________________________________________
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: Is Apple's singleton sample code correct? (From: Jeff Laing <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Rotate an image (was Re: Transform and NSImageView)
  • Next by Date: Re: Switching international keyboards programmatically
  • Previous by thread: Re: Is Apple's singleton sample code correct?
  • Next by thread: Re: Is Apple's singleton sample code correct?
  • Index(es):
    • Date
    • Thread