flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kessler CTR Mark J <mark.kessler....@usmc.mil>
Subject RE: Singleton question
Date Fri, 14 Nov 2014 12:00:46 GMT
+1


private static var _instance:ModelLocator;
public static function getInstance():ModelLocator
{
  if(! _instance)
    _instance = new ModelLocator();
  return _instance;
}


Only creating new instance when one isn't present.   Since it's static, it should only be
done once.

-Mark


-----Original Message-----
From: Harbs [mailto:harbs.lists@gmail.com]
Sent: Friday, November 14, 2014 3:54 AM
To: users@flex.apache.org
Subject: Re: Singleton question

No. That’s wrong. It should be:

private static var _instance:ModelLocator;
public static function getInstance():ModelLocator
{
  if(! _instance)
    _instance = new ModelLocator();
  return _instance;
}

(No else, and you need to assign _instance.)

Mime
View raw message