我想定义一个Singleton基本类型可供用户会从中得到他的课,所以这是我的想法:是否可以在PHP中定义一个接口Singleton?
interface SingletonInterface {
public static function getInstance();
}
abstract class SingletonAbstract implements SingletonInterface {
abstract protected function __construct();
final private function __clone() {}
}
但是,使用这种形式给出,用户可以实现这个单...
class BadImpl implements SingletonInterface {
public static function getInstance() {
return new self;
}
}
你会怎么做?
*(相关)* [单身人士有什么好坏](http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons) – Gordon 2010-08-19 06:51:23