Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-09-2006, 08:46 AM   #1
CDHBookingEdge
Registered User
 
Join Date: Oct 2006
Posts: 383
Send a message via MSN to CDHBookingEdge
Default A question for Tink on his Singleton class.

I was bumming around early in the morning and came across JAM and noticed your "Stricter Singleton" and I was wondering if you could elucidate on it a bit more. Like, how is it stricter? And how do you recommend it's proper usage and such.

Thanks in advance,
Christopher
CDHBookingEdge is offline   Reply With Quote
Old 11-09-2006, 09:14 AM   #2
Tink
Addict
 
Tink's Avatar
 
Join Date: Nov 2001
Location: London
Posts: 2,128
Default

In AS there are no private constructors which means you can't create the normal Singleton, as if the constructor is public, you can great more instances of it. In that code the getInstance() sets a var which the constructor checks. If this var isn't true (and it can only be set in getInstance()), then the constructor will throw an error.

There a few decent methods up there now, and another in the comments here http://www.tink.ws/blog/stricter-singletons/.

I posted it as there was original a singleton on there, that you could actually create more than one instance of.
Tink is offline   Reply With Quote
Old 11-09-2006, 09:21 AM   #3
CDHBookingEdge
Registered User
 
Join Date: Oct 2006
Posts: 383
Send a message via MSN to CDHBookingEdge
Default

Ahh! Trices? So that's a no go eh? Good to know. I was planning on using yours when I need it anyway but good to know about that. *grins*

Christopher
CDHBookingEdge is offline   Reply With Quote
Old 11-09-2006, 09:29 AM   #4
Tink
Addict
 
Tink's Avatar
 
Join Date: Nov 2001
Location: London
Posts: 2,128
Default

I'm not sure its there anymore, or its been edited. you could get round it using something like.

var singleton0:Singleton = new Singleton( Singleton.getInstance );
var singleton1:Singleton = new Singleton( Singleton.getInstance );

and you'd have 2 instances. Theres check in his to make sure there is only one instance so it can't have been that one.
Tink is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie class extension question cnatale ActionScript 2.0 3 08-11-2006 03:44 AM
Class setInterval question manorius ActionScript 2.0 0 07-12-2006 08:38 AM
scope in a Class question! mikey99 ActionScript 2.0 5 06-18-2006 10:05 AM
Transition class question wharfrat ActionScript 2.0 4 05-30-2005 02:43 PM
Custom member class question amerywu Flash Remoting 1 05-16-2005 07:17 AM


All times are GMT. The time now is 02:38 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.