Re: Singleton classes in ObjC
Re: Singleton classes in ObjC
- Subject: Re: Singleton classes in ObjC
- From: "Erik D. Holley" <email@hidden>
- Date: Fri, 6 Feb 2004 09:07:37 -0700
Bradley,
There are more than one Singleton design patterns (paradoxical, isn't
it?).
We can implement a singleton class design by adopting a simple protocol:
@protocol Singleton
+ (id)alloc;
+ (id)instance;
@end
Our simple pattern will yield the following results:
1) Any class can become a singleton regardless of inheritance. We will
implement the singleton as a protocol, thus your class can inherit from
any you wish then turn itself into a singleton.
2) There can be many classes defined as singletons in their own right.
There is not just one singleton class in your entire program, you may
have many various singleton flavors for various purposes.
3) Singleton instances are not allocated until first used. No need to
have a bunch of allocated singletons that may never be used.
4) Once deallocated, a singleton can never be used again, thus
enforcing the concept of "singleton." In this repsect, a singleton
doesn't live until instantiated and can't come back to life after
deallocation.
5) Singletons don't respond to alloc. Code readability is confused when
calling alloc repeatedly for a singleton instance.
I'm not sure if this list has a limit to the length of a post, so If
you're interested, you can read the more at:
http://www.holleytree.com/objc/singleton.rtf
-Erik
On Feb 5, 2004, at 11:16 AM, Bradley Smith wrote:
Is there a simple Objective-C analogue to this Java class?
--
Erik D. Holley
email@hidden
_______________________________________________
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.