Nope, you can still call new Singleton(null) and the compiler won't say
anything :-)
The 'enforcer' is required because of this loophole.

Thanks,
Om

On Mon, Nov 16, 2015 at 2:36 AM, Michael Schmalle <teotigraphix...@gmail.com
> wrote:

> On Mon, Nov 16, 2015 at 4:14 AM, OmPrakash Muppirala <bigosma...@gmail.com
> >
> wrote:
>
> > Purely pedantic, but the code does not do anything to 'enforce' the
> > singleton-ness of the class.
> >
>
> The compiler won't even let you compile this code, so the != is just sauce
> that never gets eaten. Since you have to pass an instance of
> SingletonEnforcer, it's private and the compiler will bitch.
>
> Mike.
>
>
> >
> > It should actually be:
> > public function Singleton(e:SingletonEnforcer){
> >   if(e != null)
> >   {
> >      trace("new instance of singleton created");
> >   }
> > }
> >
> > On Mon, Nov 16, 2015 at 12:54 AM, yishayw <yishayj...@hotmail.com>
> wrote:
> >
> > > Actually the comment above 'class SingletonEnforcer' explains it.
> > >
> > > package{
> > >     public class Singleton{
> > >         private static var _instance:Singleton=null;
> > >         public function Singleton(e:SingletonEnforcer){
> > >             trace("new instance of singleton created");
> > >         }
> > >         public static function getInstance():Singleton{
> > >             if(_instance==null){
> > >                 _instance=new Singleton(new SingletonEnforcer());
> > >             }
> > >             return _instance;
> > >         }
> > >     }
> > > }
> > > //I’m outside the package so I can only be accessed internally
> > > class SingletonEnforcer{
> > > //nothing else required here
> > > }
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://apache-flex-development.2333347.n4.nabble.com/FlexJS-FalconJX-Internal-Classes-tp50091p50102.html
> > > Sent from the Apache Flex Development mailing list archive at
> Nabble.com.
> > >
> >
>

Reply via email to