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 16:33:05 +0000
On Thursday, February 12, 2004, at 02:39 pm, Clark Cox wrote:
There's nothing about the code posted that says "singleton" to me, in
fact, it prevents any instances of MyAbstractClass (except for
subclasses) from ever being created.
ah right, that explains the reason and thinking for it. so that code
which goes into the abstract class doesn't make a singleton, it makes
a, well, neverton.
I'll try walk you through the method:
"if ([MyAbstractClass self] == self)"
This will be true if someone is trying to directly allocate an
instance of MyAbstractClass (i.e. not a subclass).
"return NSAllocateObject([MyConcreteClass self], 0, zone);"
This line will then allocate an instance of MyConcreteClass. The
result will be that any attempt to directly allocate MyAbstractClass
will get an instance of MyConcreteClass instead.
"return [super allocWithZone:zone];"
If, on the other hand, someone is trying to allocate a subclass, let
the allocation proceed normally
yup, i get it now -- thanks very much for the explanation.
ben
--
Clark S. Cox III
email@hidden
http://homepage.mac.com/clarkcox3/
http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html
<smime.p7s>
_______________________________________________
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.