{"id":1624,"date":"2010-01-08T16:26:32","date_gmt":"2010-01-08T07:26:32","guid":{"rendered":"http:\/\/blog.bitmeister.jp\/?p=1624"},"modified":"2010-01-15T11:51:34","modified_gmt":"2010-01-15T02:51:34","slug":"actionscript30%e3%81%a7singleton%e3%83%91%e3%82%bf%e3%83%bc%e3%83%b3%e3%82%92%e5%ae%9f%e8%a3%85%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.bitmeister.jp\/?p=1624","title":{"rendered":"ActionScript3.0\u3067Singleton\u30d1\u30bf\u30fc\u30f3\u3092\u5b9f\u88c5\u3059\u308b"},"content":{"rendered":"<p>\u6700\u8fd1\u3001ActionScript3.0\u3067\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u307e\u3059\u3002\u5f53\u7136\u3001\u4eca\u307e\u3067\u4f7f\u3063\u3066\u3044\u305f\u8a00\u8a9e\u3068\u306f\u69d8\u3005\u306a\u4ed5\u69d8\u4e0a\u306e\u9055\u3044\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u305d\u306e\u4e2d\u3067\u3061\u3087\u3063\u3068\u56f0\u3063\u305f\u306e\u306f\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306bprivate\u5c5e\u6027\u3092\u6307\u5b9a\u3067\u304d\u306a\u3044\u3053\u3068\u3002Singleton\u30d1\u30bf\u30fc\u30f3\u306a\u3069\u3092\u5b9f\u88c5\u3057\u3088\u3046\u3068\u3057\u3066private\u306a\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u5ba3\u8a00\u3059\u308b\u3068\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u300cA constructor can only be declared public.\u300d\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u5c0f\u3055\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u3042\u308c\u3070\u300c\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3057\u306a\u3044\u3088\u3046\u306b\u6ce8\u610f\u3059\u308b\u300d\u3068\u3044\u3046\u3053\u3068\u3067\u3082\u306a\u3093\u3068\u304b\u306a\u308a\u307e\u3059\u304c\u3001\u3084\u306f\u308a\u3069\u3046\u3057\u3066\u3082\u5bdd\u899a\u3081\u304c\u60aa\u3044\u306e\u3067\u3001\u5bfe\u7b56\u3092\u8003\u3048\u3066\u307f\u307e\u3059\u3002<br \/>\n<!--more--><\/p>\n<p>\u307e\u305a\u306f\u3001\u6bce\u5ea6\u304a\u99b4\u67d3\u307f\u306eGoogle\u5148\u751f\u306b\u3088\u308b\u3068\u3001\u3069\u3046\u3084\u3089\u6b21\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u304c\u5b9a\u77f3\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n<pre class=\"c\" name=\"code\">\r\npackage  \r\n{\r\n\timport flash.errors.IllegalOperationError;\r\n\t\r\n\tpublic class Singleton\r\n\t{\r\n\t\tprivate static var instance:Singleton;\r\n\t\tprivate static var internally:Boolean = false;\r\n\t\t\r\n\t\tpublic static function getInstance():Singleton {\r\n\t\t\tif (instance == null) {\r\n\t\t\t\tinternally = true;\r\n\t\t\t\tinstance = new Singleton();\r\n\t\t\t}\r\n\t\t\treturn instance;\r\n\t\t}\r\n\t\t\r\n\t\tpublic function Singleton() \r\n\t\t{\r\n\t\t\tif (!internally) {\r\n\t\t\t\tthrow new IllegalOperationError(\r\n\t\t\t\t\t\"Should not be instantiated!!\");\r\n\t\t\t}\r\n\t\t\tinternally = false;\r\n\t\t}\r\n\t\t\r\n\t\tpublic function doSomething():void {}\r\n\t\t\r\n\t}\r\n\t\r\n}\r\n<\/pre>\n<p>private static\u306e\u30d5\u30e9\u30b0\u5c5e\u6027\u3092\u6301\u3061\u3001\u5185\u90e8\u3067\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3059\u308b\u5834\u5408\u306f\u30d5\u30e9\u30b0\u3092true\u306b\u8a2d\u5b9a\u3057\u3066\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u306f\u3001\u3053\u306e\u30d5\u30e9\u30b0\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3001\u30d5\u30e9\u30b0\u304ctrue\u3067\u306a\u3051\u308c\u3070\u30a8\u30e9\u30fc\u3092throw\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001ActionScript3.0\u304b\u3089\u53ef\u80fd\u306b\u306a\u3063\u305f\u3001package\u5916\u3067\u306e\u30af\u30e9\u30b9\u5ba3\u8a00\u3092\u4f7f\u3063\u305f\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"c\" name=\"code\">\r\npackage  \r\n{\r\n\timport flash.errors.IllegalOperationError;\r\n\t\r\n\tpublic class Singleton\r\n\t{\r\n\t\tprivate static var instance:Singleton;\r\n\t\t\r\n\t\tpublic static function getInstance():Singleton {\r\n\t\t\tif (instance == null) {\r\n\t\t\t\tinstance = new Singleton(new Internal());\r\n\t\t\t}\r\n\t\t\treturn instance;\r\n\t\t}\r\n\t\t\r\n\t\tpublic function Singleton(internally:Internal) \r\n\t\t{\r\n\t\t\tif (internally == null) {\r\n\t\t\t\tthrow new IllegalOperationError(\r\n\t\t\t\t\t\"Should not be instantiated!!\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic function doSomething():void {}\r\n\r\n\t}\r\n\r\n}\r\n\r\nclass Internal {\r\n\t\r\n}\r\n<\/pre>\n<p>\u3053\u308c\u306f\u3001package\u5916\u306b\u5ba3\u8a00\u3057\u305f\u30af\u30e9\u30b9\u304c\u3001\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u5185\u304b\u3089\u3057\u304b\u53c2\u7167\u3067\u304d\u306a\u3044\u3053\u3068\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002Internal\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u751f\u6210\u3067\u304d\u306a\u3051\u308c\u3070\u3001Singleton\u30af\u30e9\u30b9\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u51fa\u6765\u305a\u3001null\u3092\u6e21\u3057\u305f\u3068\u3057\u3066\u3082\u5b9f\u884c\u6642\u306b\u30a8\u30e9\u30fc\u304cthrow\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u306a\u304c\u3089\u3001\u3053\u308c\u3089\u306e\u65b9\u6cd5\u3067\u306f\u3001\u30b3\u30fc\u30c9\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u5b9f\u884c\u3057\u3066\u307f\u306a\u3051\u308c\u3070\u3001\u30a8\u30e9\u30fc\u306e\u5b58\u5728\u304c\u308f\u304b\u308a\u307e\u305b\u3093\u3002\u305d\u3053\u3067\u3001\u3053\u3093\u306a\u65b9\u6cd5\u3092\u8003\u3048\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"c\" name=\"code\">\r\npackage  \r\n{\r\n\timport flash.errors.IllegalOperationError;\r\n\t\r\n\tpublic class Singleton\r\n\t{\r\n\t\tprivate static var instance:SingletonImpl;\r\n\t\t\r\n\t\tpublic static function getInstance():SingletonImpl {\r\n\t\t\tif (instance == null) {\r\n\t\t\t\tinstance = new SingletonImpl ();\r\n\t\t\t}\r\n\t\t\treturn instance;\r\n\t\t}\r\n\t\t\r\n\t}\r\n\r\n}\r\n\r\nclass SingletonImpl {\r\n\t\r\n\tpublic function SingletonImpl() {\r\n\t}\r\n\r\n\tpublic function doSomething():void {}\r\n\t\r\n}\r\n<\/pre>\n<p>package\u5916\u30af\u30e9\u30b9\u306b\u6a5f\u80fd\u3092\u5168\u3066\u5b9f\u88c5\u3057\u3001public\u30af\u30e9\u30b9\u306b\u306fstatic\u30e1\u30bd\u30c3\u30c9\u306e\u307f\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u30af\u30e9\u30b9\u306e\u30e6\u30fc\u30b6\u30fc\u304cdoSomething\u3092\u547c\u3073\u51fa\u3059\u305f\u3081\u306b\u306fSingletonImpl\u30af\u30e9\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u305a\u3001\u305d\u306e\u305f\u3081\u306b\u306fSingleton\u30af\u30e9\u30b9\u306egetInstance\u3092\u547c\u3076\u3057\u304b\u3042\u308a\u307e\u305b\u3093\u3002Singleton\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u56de\u907f\u3059\u308b\u3053\u3068\u306f\u4e0d\u53ef\u80fd\u306a\u306e\u3067\u3059\u304c\u3001Singleton\u30af\u30e9\u30b9\u304c\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3055\u308c\u305f\u3068\u3057\u3066\u3082\u3001SingletonImpl\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u552f\u4e00\u3067\u3042\u308b\u3053\u3068\u306f\u4fdd\u305f\u308c\u307e\u3059\u3002<\/p>\n<p>\u5192\u982d\u306b\u3082\u66f8\u3044\u305f\u901a\u308a\u3001\u307e\u3060ActionScript\u3092\u4f7f\u3044\u59cb\u3081\u305f\u3070\u304b\u308a\u306a\u306e\u3067\u3001\u4f55\u304b\u843d\u3068\u3057\u7a74\u304c\u3042\u308b\u306e\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u3002\u4f55\u304b\u30b3\u30e1\u30f3\u30c8\u304c\u3042\u308c\u3070\u3001\u3054\u6307\u6458\u3044\u305f\u3060\u3051\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u3001ActionScript3.0\u3067\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u307e\u3059\u3002\u5f53\u7136\u3001\u4eca\u307e\u3067\u4f7f\u3063\u3066\u3044\u305f\u8a00\u8a9e\u3068\u306f\u69d8\u3005\u306a\u4ed5\u69d8\u4e0a\u306e\u9055\u3044\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u305d\u306e\u4e2d\u3067\u3061\u3087\u3063\u3068\u56f0\u3063\u305f\u306e\u306f\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306bprivate\u5c5e\u6027\u3092\u6307\u5b9a\u3067\u304d\u306a\u3044\u3053\u3068\u3002Singlet [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[64,63,40],"class_list":["post-1624","post","type-post","status-publish","format-standard","hentry","category-tech","tag-as3","tag-flash","tag-40"],"_links":{"self":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/1624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1624"}],"version-history":[{"count":6,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/1624\/revisions"}],"predecessor-version":[{"id":1630,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/1624\/revisions\/1630"}],"wp:attachment":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}