Inheriting the original object and rewriting the module to be changed is the proxy pattern.
<?php class CD{ protected $name; protected $price; protected $num; function __construct($name, $price, $num){ $this->name = $name; $this->price = $price; $this->num = $num; } function buy(){ echo $this->_pay().',已经完成了购买!'; } function _pay(){ return "使用农业银行支付!"; } } /* * 新的支付手段出现我们要切换到其他支付手段 * */ class Buyproxy extends CD{ function _pay(){ return "使用支付宝进行支付!"; } } $buy = new BuyProxy("《乌云背后的幸福线》", "43$", "3"); $buy->buy();
The above has introduced the 16php proxy mode, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.