singleton pattern in cocoa

2009-09-14 Thread Manuel Grau
Hi all, As I come from java world, I was trying to implement the singleton pattern, very usual in java. After searching in internet I found this code from wikipedia: @interface MySingleton : NSObject { } + (MySingleton *)sharedSingleton; @end @implementation MySingleton static MySingleto

Re: singleton pattern in cocoa

2009-09-14 Thread Bryan Henry
This question usually gets asked at least a couple times a month. I suggest you look up the previous responses on CocoaBuilder (http://www.cocoabuilder.com/ ), which archives responses on this mailing list if you want an exhaustive response, since all solutions have been mentioned somewhere

Re: singleton pattern in cocoa

2009-09-14 Thread Dave DeLong
Singleton implementation is something that you see debated back and forth every now and then. People argue about the values over overriding -retain, -release, -autorelease, and so on. I really like Peter Hosey's analysis (and implementation) that he's posted on his blog: http://boredzo.o

Re: singleton pattern in cocoa

2009-09-14 Thread Christopher J Kemsley
About the only thing that I'd recommend is that the "static" be inside the +sharedSingleton method so that you aren't able to take the cheap- way-out and call that variable directly in other class methods before it's created. For the rest of it: it seems to follow Apple's patterns - for in

Re: singleton pattern in cocoa

2009-09-14 Thread Jean-Daniel Dupas
Definition of true singleton is generally discouraged and not really useful. See more info about it here: http://eschatologist.net/blog/?p=178 Le 10 sept. 2009 à 22:07, Manuel Grau a écrit : Hi all, As I come from java world, I was trying to implement the singleton pattern, very usual i

Re: singleton pattern in cocoa

2009-09-14 Thread Alex Kac
Probably best to use Apple's example: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW32 I love Google, but I always prefer to look at Apple's docs first. I found the above by going to de