对原对象进行继承并重写要被改变的模块,这就是代理模式。
<?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();以上就介绍了16php代理模式,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号