码迷,mamicode.com
首页 > 其他好文 > 详细

抽象工厂模式

时间:2017-12-22 00:33:20      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:模式   mysql   gpo   ace   factor   配置文件   div   工厂   nbsp   

interface Factory {
public static function getDB();   //接口里的类不用实现,下面的子类来具体实现
}

class MySQLFactory implements Factory {
public static function getDB() {
return new MySQL();
}
}

class SqliteFactory implements Factory {
public static function getDB() {
return new Sqlite();
}
}

class MyPDOFactory implements Factory {
public static function getDB() {
return new MyPDO();
}
}


// 配置文件
$fact = ‘MyPDOFactory‘;
$db = MyPDOFactory::getDB();
print_r($db);

抽象工厂模式

标签:模式   mysql   gpo   ace   factor   配置文件   div   工厂   nbsp   

原文地址:http://www.cnblogs.com/aiit/p/8082898.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!