Created
August 23, 2016 08:29
-
-
Save area73/c822fd847b7102fb2200975dc7ecce5b to your computer and use it in GitHub Desktop.
Singleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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