ActionScript3 シングルトンデザインパターン
最新ソース
package
{
/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
public class Singleton
{
private static var instance:Singleton = null;
public function Singleton()
{
//statement
if (instance == null) {
trace("Singleton Object");
instance = this;
} else {
trace("にゅーしてあるよ!");
throw new Error("singleton class!");
}
}
public static function getinstance():Singleton
{
//statement
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}
}
呼び出し
Singleton.getinstance();
new Singleton();
など
感想・考察・その他
過去ソース1:これで合ってるのかな。
追記
5.6.09 12:07 間違ってた。わからん。
5.6.09 12:34 参考のモノと同じになった。ていうか、クラスメソッドスタティックメソッドいらねぇんじゃね。
参考
trick7:FlashとSingletonパターン
機関誌/2008年度夏季機関誌/sc15_Singleton Pattern in ActionScript3.0
moriBlog:AS3でデザインパターン -Singleton(シングルトン)-
最新ソース
package
{
/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
public class Singleton
{
private static var instance:Singleton = null;
public function Singleton()
{
//statement
if (instance == null) {
trace("Singleton Object");
instance = this;
} else {
trace("にゅーしてあるよ!");
throw new Error("singleton class!");
}
}
public static function getinstance():Singleton
{
//statement
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}
}
呼び出し
Singleton.getinstance();
new Singleton();
など
感想・考察・その他
過去ソース1:
追記
5.6.09 12:07 間違ってた。わからん。
5.6.09 12:34 参考のモノと同じになった。ていうか、
参考
trick7:FlashとSingletonパターン
機関誌/2008年度夏季機関誌/sc15_Singleton Pattern in ActionScript3.0
moriBlog:AS3でデザインパターン -Singleton(シングルトン)-
AS3 デザインパターン [Singleton]の続きを読む
