Skip to content

Instantly share code, notes, and snippets.

@area73
Created August 23, 2016 08:29
Show Gist options
  • Save area73/c822fd847b7102fb2200975dc7ecce5b to your computer and use it in GitHub Desktop.
Save area73/c822fd847b7102fb2200975dc7ecce5b to your computer and use it in GitHub Desktop.
Singleton
package {
public class ClaseSingleton {
static private var _instance:ClaseSingleton;
/**
* Singleton constructor. It has a refference to an internal
* class to avoid a new object been created acidentally
* */
public function ClaseSingleton(singletonEnforcer:SingletonEnforcer){}
//public function TotalLayout(){}
public static function getInstance():ClaseSingleton {
if(ClaseSingleton._instance == null) {
ClaseSingleton._instance = new ClaseSingleton(new SingletonEnforcer());
}
return ClaseSingleton._instance;
}
}
}
/**
* Internal class to reinforce instantiation from getInstance
**/
class SingletonEnforcer {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment