16php proxy mode

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 09:05:521286browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn