首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

两个简略的php设计模式

2012-10-23 
两个简单的php设计模式1.单例模式不管多少次实例化类,都只有一个实例存在,适合数据库操作interface Hello{

两个简单的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();

热点排行