单例是因为一个就足够了,多了浪费class TestClass {
private static $_instance;
public static function getInstance(){
if(!(self::$_instance instanceof self)){
self::$_instance = new self;
}
return self::$_instance;
}
}实际中用作数据库连接类和工厂模式一起使用,根据参数调用单例模式,可以提高资源使用效率。
1520

被折叠的 条评论
为什么被折叠?



