策略模式
class discountYH {
function __construct() {
}
public function YH($x, $y) {
return $x * $y;
}
}
class addYH {
function __construct() {
}
public function YH($x, $y) {
return $x + $y;
}
}
class YH {
private $cls;
public function YH($yhcls){
$this->cls = $yhcls;
}
public function getResult($x, $y) {
return $this->cls->YH($x, $y);
}
}
$yh = new YH(new discountYH());
$yh->getResult($x, $y);
$yh_ = new YH(new addYH());
$yh_->getResult($x, $y);