抽象工厂模式

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);

posted @ 2017-12-21 23:06  mayer326  阅读(95)  评论(0编辑  收藏  举报