본문 바로가기

삽질하기/Flex

Flex Singleton Pattern

반응형

package {
   public class MyClass {
      private static var _instance:MyClass
  
      public function MyClass(enforcer:SingletonEnforcer) {

      }
  
      public static function getInstance():MyClass {
         if(MyClass._instance == null) {
            MyClass._instance = new MyClass(new SingletonEnforcer());
         }
      }
   }
}

class SingletonEnforcer {}

var instance:MyClass = MyClass.getInstance();