• 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 Apple's singleton sample code correct?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is Apple's singleton sample code correct?


  • Subject: Re: Is Apple's singleton sample code correct?
  • From: Shaun Wexler <email@hidden>
  • Date: Thu, 1 Dec 2005 21:03:02 -0800

On Dec 1, 2005, at 8:41 PM, Jeff Laing wrote:

Its probably arguable as to whether your use of the singleton pattern for
the above matrix of coefficients is appropriate. I think Malcolm has
already pointed out other people confusing "singleton" with "shareable,
cached object".

Yes, my NSColor example might have confused the issue, since it would maintain its own immutable shared objects internally, rather than having a distinct subclass for each color... egad!

Nevertheless, I wasn't saying that there isn't a case for MortalSingleton -
its a worthwhile contribution to the Cocoa world.

I agree; it should be placed into Apple's sample code, along with an ImmortalSingleton class and possibly a few others. Mmalc, go ahead and use it; I'd be happy to contribute more examples. I also use a pooled object class, where you can request all instances of a particular class (BTW that used to be called SKWManagedObject until CoreData kinda stomped on my namespace, er namesake). Maybe I'll just open-source my base framework next year?

What I was saying was that *I* dont understand why you'd *copy* a real
singleton, ie one of those objects of the class for which there should only
ever be one instance.

For example, NSDictionary -setObject:forKey: copies the key object. If you raised an exception upon -copy, you couldn't use a singleton as a key into a dict.

And because I can't concieve of a scenario where that would be rational, I'd
be inclined to prevent it from happening, rather than silently allow
misguided attempts from thinking they'd succeeded. Which is what the Apple
sample code does with -release.

You could have development/debug builds conditionally defined, and only throw exceptions in production code, but skip it in released code. There isn't "only one way" to write a good program... ;)
--
Shaun Wexler
MacFOH
http://www.macfoh.com

"Society often forgives the criminal; it never forgives the dreamer." - Oscar Wilde


_______________________________________________
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
References: 
 >RE: Is Apple's singleton sample code correct? (From: Jeff Laing <email@hidden>)

  • Prev by Date: Re: What is the best way to use NSOutlineView without NSTreeController?
  • Next by Date: Re: Is Apple's singleton sample code correct?
  • Previous by thread: RE: Is Apple's singleton sample code correct?
  • Next by thread: Re: Is Apple's singleton sample code correct?
  • Index(es):
    • Date
    • Thread