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);
```
- 空白目錄
- 安裝
- linux下安裝nginx
- linux下安裝php
- 調試
- windows 安裝wamp
- 常用源
- 類型
- Boolean布爾類型
- Integer整型
- Float浮點型
- String字符串
- Array數組
- Object對象
- Resource資源類型
- NULL
- Callback/Callable類型
- 類型轉換
- 變量
- 預定義變量
- 常量
- 魔術常量(預定義常量)
- 語法
- 運算符
- 流程控制
- 條件語句
- if
- else
- else if/elseif
- switch
- 循環語句
- while
- do-while
- for
- foreach
- break
- return
- continue
- require
- include
- require_once
- include_once
- 函數
- 內置函數
- 匿名函數
- 自定義函數
- 類與對象
- 屬性
- 聲明
- public
- protected
- private
- 類常量
- 方法
- 魔術方法
- __construct()
- __destruct()
- __call()
- __callStatic()
- __get()
- __set()
- __isset()
- __unset()
- __sleep()
- __wakeup()
- __toString()
- __invoke()
- __set_state()
- __clone()
- __debugInfo()
- 方法的調用
- ->(對象運算符)
- ::(范圍解析操作符)
- 設計模式
- 依賴注入
- call_user_func
- is_callable (
- 創建型模式
- 工廠方法模式
- 抽象工廠模式
- 單例模式
- 建造者模式
- 原型模式
- 結構性模式
- 適配器模式
- 裝飾器模式
- 代理模式
- 外觀模式
- 橋接模式
- 組合模式
- 享元模式
- 行為型模式
- 策略模式
- 模板方法模式
- 觀察者模式
- 迭代子模式
- 責任鏈模式
- 命令模式
- 備忘錄模式
- 訪問者模式
- 中介者模式
- 解釋器模式
- 六大原則
- uml語言
- 反射
- 類型約束
- 調試
- lamp
- lnmp
- composer
- 工作常用
- UML圖
- 常見問題