//-----------抽象产品角色------------
//定义保险产品工厂获取产品
interface InsuranceProduct
{
public function getProductList();
}
//-----------具体产品角色------------
//众安保险
class ZhongAn implements InsuranceProduct {
public function getProductList()
{
return "ZhongAn Insurance ProductList";
}
}
//小雨伞保险
class XiaoYuSan implements InsuranceProduct {
public function getProductList()
{
return "XiaoYuSan Insurance ProductList";
}
}
//齐欣保险
class QiXin implements InsuranceProduct {
public function getProductList()
{
return "QiXin Insurance ProductList";
}
}
//-----------抽象工厂类------------
interface Factory
{
public function create();
}
//-----------继承工厂类, 用于实例化产品------------
class ZhongAnFactory implements Factory
{
public function create()
{
return new ZhongAn();
}
}
class XiaoYuSanFactory implements Factory
{
public function create()
{
return new XiaoYuSan();
}
}
class QiXinFactory implements Factory
{
public function create()
{
return new QiXin();
}
}
//-----------具体操作类------------
class Client
{
public function test()
{
$qiXinResult = new QiXinFactory();
echo $qiXinResult->create()->getProductList();
$xiaoYuSanResult = new XiaoYuSanFactory();
echo $xiaoYuSanResult->create()->getProductList();
}
}
$lala = new Client();
$lala->test();
网友评论