Re: Creating shared classes
Re: Creating shared classes
- Subject: Re: Creating shared classes
- From: Art Isbell <email@hidden>
- Date: Wed, 18 Jul 2001 12:49:19 -1000
On Wednesday, July 18, 2001, at 07:46 AM, Brendan Younger wrote:
/// UserSession.m
#import "UserSession.h"
static UserSession* mainUserSession = nil;
@implementation UserSession
- (id)init {
return [super init];
}
Designing a singleton class can be a little tricky. As long
as everyone invokes sharedUserSession, things are cool as is.
But maybe you want to ensure a singleton if someone invokes
[[UserSession alloc] init]. In this case, you'd want init to
check for the existence of mainUserSession. If it exists, you'd
need to release self and set self to mainUserSession. If
mainUserSession doesn't exist, then set mainUserSession to self.
You might also want to prevent the singleton object from
being (auto)released. If so, you'd need to override release and
autorelease to do nothing.
But you should implement dealloc to clean up. It would need
to set mainUserSession to nil as well.
Art Isbell
Apple iServices Technical Support
http://www.apple.com/iservices/webobjectssupport/
+1-808-591-0836