您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP模板+工厂设计模式

2025/10/14 11:50:24发布21次查看
```addapple(); $this->addpineapple(); } abstract protected function addapple(); abstract protected function addpineapple();}//创建一个子类实现父类的模板内的方法class tf extends fruit{ protected function addapple() { //生成一个工厂 $this->apple = new applefactory(); //调用方法 echo $this->apple->dofactory(); } protected function addpineapple() { $this->pineapple = new pineapplefactory(); echo $this->pineapple->dofactory(); }}class pineapplefactory extends creator{ protected function dofacorymethod() { $product = new pineapple(); return $product->getattribute(); }}class pineapple implements product{ private $mfg; public function getattribute() { $this->mfg = pineapple; return $this->mfg; }}abstract class creator{ abstract protected function dofacorymethod(); public function dofactory(){ $mfg = $this->dofacorymethod(); return $mfg; }}//设置一个产品的接口interface product{ public function getattribute();}class applefactory extends creator{ protected function dofacorymethod() { $product = new apple(); return $product->getattribute(); }}class apple implements product{ private $mfg; public function getattribute() { $this->mfg = apple; return $this->mfg; }}class client{ public function __construct() { $qq = new tf(); $qq->templatemethod(); }}$data = new client();```
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product