|
Well you could throw an Error if the
parameter passed in was null too… From:
[email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Williams 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: 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 From: I was supposing that don't have private constructors
was due to the alpha state of the player, but it seems like is something
deliberated. IMHO, I don't agree with this design languaje issue cause patterns
like singletons are widely used and people expect to use in the standard way. I
don't want to argue but would like the guys behind this responsability to think
about it a bit and think about what their users expect to find when deal with
the languaje. Thanks for listening :) 2006/2/10,
Johannes Nel <[EMAIL PROTECTED]>: so even if i create a private class that is only
accecible in that package (and then on package level declare a accesor for it) the
only way i can be certain that class will only be created once is by having
nothing else in that package. this does not seem right. On 2/10/06, Matt Chotin < [EMAIL PROTECTED]>
wrote: You have to simulate
private constructors by having the constructor take a class that is
inaccessible to other classes (namely putting that class in the same file as
the singleton outside of the package block). Unfortunately I believe the
rule is that the constructor of the class has to have the same visibility as
the class itself. So public classes need public constructors, internal
classes get internal constructors, etc. Matt From: [email protected]
[mailto:[email protected]]
On Behalf Of Johannes Nel abstract classes i am not expecting, private constructers i certainly
hope for On 2/9/06, Carlos
Rovira <[EMAIL PROTECTED]
> wrote: Hi,
|
- Re: [flexcoders] AS3 class constructors can't be private... Carlos Rovira
- RE: [flexcoders] AS3 class constructors can't be pr... Matt Chotin
- RE: [flexcoders] AS3 class constructors can't b... Geoffrey Williams
- Re: [flexcoders] AS3 class constructors can't be pr... Johannes Nel
- RE: [flexcoders] AS3 class constructors can't be pr... Matt Chotin
- RE: [flexcoders] AS3 class constructors can't b... Geoffrey Williams
- RE: [flexcoders] AS3 class constructors can't be pr... Roger Gonzalez
- Re: [flexcoders] AS3 class constructors can't b... Carlos Rovira
- Re: [flexcoders] AS3 class constructors can... Jens Halm
- Re: [flexcoders] AS3 class constructors... Carlos Rovira
- Re: [flexcoders] AS3 class constru... Xavi Beumala
- Re: [flexcoders] AS3 class con... Michael Hansen
- Re: [flexcoders] AS3 class... Julian Suggate
- Re: [flexcoders] AS3 class... Michael Hansen
- Re: [flexcoders] AS3 class... Jens Halm

