e-Commerce project we may encounter such a problem: to change the price of different products, but the product is a huge difference, this time it is appropriate to use the intermediary model.
name = $name; $this->price = $price; $this->obj = $obj; } function Changprice ($newprice) {$this->obj->change ($this, $newprice); }}/* * Actual class differences are very large may not be able to create parent class * */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); }}/* * Mediator Class * * */class intermediar{Public Function Change ($obj, $value) {$obj->price = $value; }} $inter = new Intermediar (), $label = new book ("Book", $inter), $label->changprice (Var_dump); ($label);
The above describes the 14 intermediary mode, including the content, I hope the PHP tutorial interested in a friend helpful.