Re: Is Apple's singleton sample code correct?
Re: Is Apple's singleton sample code correct?
- Subject: Re: Is Apple's singleton sample code correct?
- From: j o a r <email@hidden>
- Date: Sat, 26 Nov 2005 18:39:26 +0100
Hello,
I think that this thread, while interesting from a theoretical point
of view, it's just way out of line from a practical point of view. I
think there are signs of over-engineering. Just look at the
documentation under discussion:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaObjects/Articles/CreateSingleton.html>
* Why mix in "@synchronized() {}" in this example at all? Leave that
to the multi-threading topics!
* Why spend all that time on overriding retain / release, et.c.? If
you're not a framework developer, I would say that it's mostly a
complete waste of time.
Seriously - how often have you had a problem with your singleton
pattern classes that would have been resolved by this type of
safeguards? I don't think I've ever had a problem of that nature, so
I don't see the benefit of adding this complexity.
I also think that it's obvious from the discussions in this tread
that attempting to add these safeguards most often creates more bugs
that it would possibly solve.
Just keep it simple!
@interface MySingletonClass : NSObject
+ (MySingletonClass *) sharedInstance;
@end
@implementation MySingletonClass
+ (MySingletonClass *) sharedInstance
{
static MySingletonClass *mySharedInstance = nil;
if (nil == mySharedInstance)
{
mySharedInstance = [[MySingletonClass alloc] init];
}
return mySharedInstance;
}
@end
j o a r
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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