php设计模式---简单工厂模式
class operation{
public $numbA = 0;
public $numbB = 0;
public function result(){
}
}
class add extends operation{
public function result(){
return $this->numbA + $this->numbB;
}
}
class sub extends operation{
public function result(){
return $this->numbA - $this->numbB;
}
}
class operationFactory{
//工厂
public static function createOperation($operator){
switch ($operator){
case '+':
$oper = new add();
break;
case '-':
$oper = new sub();
break;
}
return $oper;
}
}
//客户端调用
$op = operationFactory::createOperation('+');
$op->numbA = 10;
$op->numbB = 5;
var_dump($op->result());
本人经过测试,博客每天不定时更新,每天都有好东西...
疯子在左,天才在右