Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:下次注意, 一天的作业不要分成多次提交, 不便于审核
【抽象工厂】
<?php namespace day18; // 导入商城类 use chapter5\D; use me\base\inc02\iShop; use me\base\inc02\Jd; use me\base\inc02\Duo; use me\base\inc02\Tmall; // 自动加载 require __DIR__ . '/autoload.php'; // 商城类 class Shopping2 { // 商城平台 private $shop = null; // 由抽象工厂类完成实例化依赖对象的过程 public function __construct(iShop $shop) { // 将依赖工厂类换成面向接口的抽象工厂模式 $this->shop = $shop; } // 调用外部依赖对象的方法 public function goShopping() { return $this->shop->shop() . ' --> 省钱更省心!'; } } // 客户端调用 echo (new Shopping2(new Tmall()))->goShopping() . '<br>'; echo (new Shopping2(new Duo()))->goShopping() . '<br>'; echo (new Shopping2(new Jd()))->goShopping() . '<br>'; class Shopping2_1 { public function goShopping(iShop $shop) { return $shop->shop() . ' ==> 省钱更省心!'; } } echo '<hr>'; // 客户端调用:在普通方法中调用 echo (new Shopping2_1())->goShopping(new Tmall()) . '<br>'; echo (new Shopping2_1())->goShopping(new Duo()) . '<br>'; echo (new Shopping2_1())->goShopping(new Jd()) . '<br>';