16php proxy mode

WBOY
Release: 2016-07-29 09:05:52
Original
1241 people have browsed it

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();
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!