ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
http://www.php.cn/php-weizijiaocheng-396533.html 去网购商品, 登场8折, 如果总商品费用超过200元, 就免去12.95元钱运费. ``` <?php abstract class Ihook { protected $hook; protected $fullCost; public function templateMethod($fullCost, $hook) { $this->fullCost = $fullCost; $this->hook = $hook; $this->addGoods(); $this->addShippingHook(); $this->displayCost(); } protected abstract function addGoods(); protected abstract function addShippingHook(); protected abstract function displayCost(); } class Concrete extends Ihook { protected function addGoods() { $this->fullCost = $this->fullCost*0.8; } protected function addShippingHook() { if (!$this->hook) { $this->fullCost += 12.95; } } protected function displayCost() { echo "您需要支付".$this->fullCost."元"; } } class Client { private $totalCost; private $hook; public function construct($goodsTotal) { $this->totalCost = $goodsTotal; $this->hook = $this->totalCost >= 200; $concrete = new Concrete(); $concrete->templateMethod($this->totalCost, $this->hook); } } $worker = new Client(100); $worker = new Client(200); ```