Re: Is Apple's singleton sample code correct?
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