两个简单的php设计模式
1.单例模式
不管多少次实例化类,都只有一个实例存在,适合数据库操作
interface Hello{function say_hello();}class English implements Hello{public function say_hello(){echo "Hello!";}}class Chinese implements Hello{public function say_hello(){echo "你好";}}class speak{public static function factory($type){if($type == 1) $temp = new English();else if($type == 2) $temp = new Chinese();else{die("Not supported!");}return $temp;}}$test = Speak::factory(1);$test->say_hello();