Re: objective-c question/clarification
Re: objective-c question/clarification
- Subject: Re: objective-c question/clarification
- From: Carlos Weber <email@hidden>
- Date: Sun, 24 Jun 2001 23:11:34 -1000
On Sunday, June 24, 2001, at 07:40 , email@hidden wrote:
+ (id)sharedInfoWindowController
{
static InfoWindowController *_sharedInfoWindowController = nil;
if (!_sharedInfoWindowController)
_sharedInfoWindowController = [[InfoWindowController
allocWithZ$
return _sharedInfoWindowController;
}
The key is the word "static". Its a case of the C language raising its
ugly head. This is a quote from K&R:
"... Internal static variables are local to a particular function just
as automatic variables are, but unlike automatics, they remain in
existence rather than coming and going each time the function is
activated. This means that internal static variables provide private,
permanent storage within a single function."
I believe this is what is referred to as creating a "singleton"; I've
seen this idiom a lot, and it seems to be a way of getting around the
fact that Objective-C lacks class variables.