Singleton

ギャングオブフォー : アシアルブログ

デザインパターンのシングルトンですが、

[php]
class Singleton
{
private static $instance = null;

private function __construct() {}

public static function getInstance()
{
if (is_null(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class;
}

return self::$instance;
}
}
[/php]

「$class = __CLASS__」がにくい。クラス名を変えても、この部分を変更しなくていいですもんね。
なるほどなー

関連する記事:

Powered by

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">