• 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 this enough for a singleton? (for a class cluster "placeholder")
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: is this enough for a singleton? (for a class cluster "placeholder")
      • From: Shawn Erickson <email@hidden>
References: 
 >Re: is this enough for a singleton? (for a class cluster "placeholder") (From: Clark Cox <email@hidden>)

  • Prev by Date: Crash at window maximize
  • Next by Date: Re: Spinning wait cursor in COCOA
  • Previous by thread: Re: is this enough for a singleton? (for a class cluster "placeholder")
  • Next by thread: Re: is this enough for a singleton? (for a class cluster "placeholder")
  • Index(es):
    • Date
    • Thread