Re: is this enough for a singleton? (for a class cluster "placeholder")
Re: is this enough for a singleton? (for a class cluster "placeholder")
- Subject: Re: is this enough for a singleton? (for a class cluster "placeholder")
- From: Ben Dougall <email@hidden>
- Date: Thu, 12 Feb 2004 13:47:41 +0000
On Wednesday, February 11, 2004, at 09:56 pm, Shawn Erickson wrote:
On Feb 11, 2004, at 1:22 PM, Ben Dougall wrote:
i got this code from the archives for a singleton object:
+ (id)allocWithZone:(NSZone *)zone {
if ([MyAbstractClass self] == self)
return NSAllocateObject([MyConcreteClass self], 0, zone);
return [super allocWithZone:zone];
}
don't quite understand it -- will that give an ok/perfectly fine
singleton implementation? usually the singleton implementations that
i've seen involve a static variable in the class, but i know there's
a variety of ways to do singletons. is there something else that
needs to be done further to the above code, or is that it, so far as
the singleton aspect of it goes?
The above looks more about returning a concrete sub-class in place of
an abstract class, not a singleton.
i really do think it is for a singleton. that's clearly stated here
<
http://cocoa.mamasam.com/COCOADEV/2003/05/2/64061.php> where someone's
talking about that exact piece of code and the singleton/placeholder
aspect of it.
This is what I do for a singleton (not all is needed in theory but)...
[code snipped]
yup thanks for that code -- if i can't understand the above code i will
use another singleton implementation probably like yours, but i would
like to get to the bottom of the above bit of code first. it's so short
and simple for a start -- that's what makes me think that something
else maybe required that hasn't been said in the related posts about
it. anyone know if the above code does enough required for a reasonable
singleton implementation (for the abstract class of a class cluster in
case that makes a difference to the situation)?
thanks, ben.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.