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: David Gimeno Gost <email@hidden>
- Date: Sun, 27 Nov 2005 01:20:14 +0100
On Sat, 26 Nov 2005 09:58:04 -0800, mmalcolm crawford
<email@hidden> wrote:
I haven't found anything there stating that a singleton should never
be deallocated.
The reference states that the instance cannot be released, so this is
a natural corollary.
We're talking about different things here.
Yes, it's crystal clear that the documentation says that the singletons
provided by the Cocoa cannot be deallocated. But I'm not talking about
the singletons provided by Cocoa here, nor am I criticizing their
design in any way. Actually, I don't care what their lifetime is, nor
whether they really follow the singleton pattern or not.
What I'm saying is that the documentation that describes the singletons
provided by Cocoa does just that, describe the singletons in the Cocoa
frameworks, and as such can't be considered as a reference document
saying what the lifetime of singletons in general should be. Moreover,
I assert that they shouldn't be interpreted as saying what the lifetime
of the singletons written _using_ Cocoa should be. I'm not talking
about the singletons in the Cocoa frameworks here, but about the
singletons written by the rest of the world. That all the singletons
_provided by_ Cocoa happen to have a particular lifetime doesn't mean
that we all should write our singletons the same way, does it?
This appears to be the fundamental problem. You seem to want the
pattern to work in a particular way. It doesn't. It's been working
the way it has in Cocoa since before the Design Patterns book was
published
You have completely missed my point. On the contrary, what I'm saying
is precisely that the design of singletons in general, including those
written _using_ Cocoa (but not those _provided by_ Cocoa), shouldn't
enforce a particular variation of the pattern and that not enforcing
such arbitrary constraints makes it possible to design singletons that
can support any particular lifetime model, while at the same time being
better from any coding point of view (i.e. easier to write, easier to
understand, easier to use, safer, more reusable, etc.).
The simple fact of the matter is that you're not going to change this,
nor is it going to be recognised as a bug...
I'm not trying to change anything in Cocoa. I'm not saying that the
singletons _provided by_ Cocoa should be modified to follow a
particular variation of the singleton design pattern, nor do I care
whether they actually follow any particular variation of the pattern.
What I'm saying is that the particular variation of the singleton
design pattern used in the Cocoa frameworks themselves shouldn't be
enforced to the rest of the world. What I would consider a bug in the
documentation is any statement that said that singletons in general
should be written following the same lifetime model as the singletons
provided by Cocoa (and that would definitely be a bug regardless of
whether it would be recognized as a bug by Apple or not).
Singletons in general should use whatever variation (e.g. lifetime
model) is appropriate for them, no matter which variation of the
pattern was used in the frameworks provided by the development
environment.
Regards.
_______________________________________________
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