抽象工厂模式

Posted mayer326

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了抽象工厂模式相关的知识,希望对你有一定的参考价值。

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

以上是关于抽象工厂模式的主要内容,如果未能解决你的问题,请参考以下文章