🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
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); ```