LoginSignup
2
3

More than 5 years have passed since last update.

シングルトンパターン

Posted at

典型的なシングルトンパターンだよ。

Singleton.as

package jp.ceroan {
    import flash.errors.*;

    /**
     * Singleton
     * @author OKI Yoshiya (ceroan)
     */
    public class Singleton {
        private static var _instance:Singleton = new Singleton();

        private static var _uid:String;

        public function Singleton() {
            if (_instance) throw new IllegalOperationError("Singletonクラスはインスタンスを生成できません。");
        }

        /**
         * Singletonクラスにアクセスするためのインスタンスを取得します。
         * @return Singletonインスタンスを返します。
         */
        public static function get instance():Singleton {
            return _instance;
        }

        public function get uid():String { return _uid; }
        public function set uid(value:String):void {
            _uid = value;
        }

    }

}
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3