标签:
<?php abstract class operation{ public $num1; public $num2; public function setNum1($num1){ $this->num1 = $num1; } public function setNum2($num2){ $this->num2 = $num2; } public function getResult(){ return null; } } class add extends operation{ public function getResult(){ return $this->num1+$this->num2; } } class mul extends operation{ public function getResult(){ return $this->num1*$this->num2; } } class Factory{ public static function setOpratory($type){ switch($type){ case ‘+‘: return new add(); break; case ‘*‘: return new mul(); break; default: return null; break; } } } $cal = Factory::setOpratory(‘*‘); $cal->setNum1(4); $cal->setNum2(2); $result = $cal->getResult();
标签:
原文地址:http://www.cnblogs.com/qbyyqhcz/p/4666025.html