Ya, that would work… J

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Matt Chotin
Sent: Friday, February 10, 2006 12:53 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] AS3 class constructors can't be private? Abstract classes?

 

Well you could throw an Error if the parameter passed in was null too…

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Geoffrey Williams
Sent: Friday, February 10, 2006 9:48 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] AS3 class constructors can't be private? Abstract classes?

 

I had seen that before and didn’t like it because you could just use:

 

var _singleton:MySingleton = new MySingleton (null);

 

In any case, for anyone interested, I ended up doing something similar to the code below:

 

package whatever {

            public class SingletonClass {

                        public function SingletonClass () {

                                    if (Instantiation.locked) throw new Error ("Singleton class cannot be instantiated using the constructor.");

                        }

                        private static var __instance:SingletonClass;

                        public static function get instance ():SingletonClass {

                                    if (!__instance) {

                                                Instantiation.locked = false;

                                                __instance = new SingletonClass ();

                                                Instantiation.locked = true;

                                    }

                                    return __instance;

                        }

            }

}

class Instantiation {

            public static var locked:Boolean = true;

}


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Matt Chotin
Sent: Friday, February 10, 2006 12:24 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] AS3 class constructors can't be private? Abstract classes?

 

They did, we discussed ad infinitum, this is what we came up with.  Maybe we can improve it later but this is what we’re getting for now.  Trust us that we spent a long time discussing internally.

 

Re the package stuff, it’s about the file not the package.

 

MySingleton.as

 

package whatever {

  public class MySingleton {

    public function MySingleton(singletonEnforcer:MySingletonEnforcer) { … }

    private static var instance:MySingleton;

    pubic function getInstance():MySingleton {

      if (instance == null)

        instance = new MySingleton(new MySingletonEnforcer());

      return instance;

    }

    …

  }

}

 

//this is in MySingleton.as but is outside the package block

class MySingletonEnforcer {}

 

And that’s it.

 

Matt

 





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to