php 简单的工程模式 实现加法操作

class A{
protected $Num1;
protected $Num2;
public $result;
public function getNum1(){
return $this->Num1;
}
public function setNum1($Num1){
return $this->Num1=$Num1;

}
public function getNum2(){
return $this->Num2;
}
public function setNum2($Num2){
return $this->Num2 = $Num2;

}
public function get_result(){
return null;
}

}
class Add extends A
{
public function get_result()
{
return $this->Num1+$this->Num2;
}
}
class Faction{

public function getR($re){
if($re=="+") {
$com = new Add();
return $com;
}

}
}
$model = new Faction();

$m = $model->getR("+");
$m->setNum1(1);
$m->setNum2(27777);

print_r($m->get_result());exit;
posted @ 2018-02-28 14:03  未解  阅读(182)  评论(0编辑  收藏  举报