电商项目中我们可能遇到这样的问题:要对不同的商品修改价格,但是商品是有巨大的差别的,这个时候就适合使用中介者模式。
睿拓智能网站系统-网上商城1.0免费版软件大小:5M运行环境:asp+access本版本是永州睿拓信息专为电子商务入门级用户开发的网上电子商城系统,拥有产品发布,新闻发布,在线下单等全部功能,并且正式商用用户可在线提供多个模板更换,可实现一般网店交易所有功能,是中小企业和个人开展个人独立电子商务商城最佳的选择,以下为详细功能介绍:1.最新产品-提供最新产品发布管理修改,和最新产品订单查看2.推荐产
<?php
class Book{
private $name;
private $obj=NULL;
public $price;
function __construct($name, $price, Intermediar $obj){
$this->name = $name;
$this->price = $price;
$this->obj = $obj;
}
function changprice($newprice){
$this->obj->change($this, $newprice);
}
}
/*
* 实际情况中类差别很大可能无法创建父类
* */
class Computer{
private $name;
private $obj;
public $price;
function __construct($name, $price, Intermediar $obj){
$this->name = $name;
$this->price = $price;
$this->obj = $obj;
}
function changprice($newprice){
$this->obj->change($this, $newprice);
}
}
/*
* 中介者类
*
* */
class Intermediar{
public function change($obj, $value){
$obj->price = $value;
}
}
$inter = new Intermediar();
$label = new Book('book', 34, $inter);
$label->changprice(100);
var_dump($label);以上就介绍了14中介者模式,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。









