class YunSuan
{
public $a;
public $b;
function Jia()
{
return $this->a+$this->b;
}
function Jian()
{
return $this->a-$this->b;
}
function Cheng()
{
return $this->a*$this->b;
}
}*/
class YunSuan
{
public $a;
public $b;
function Suan()
{
echo "对两个数进行运算";
}
}
class Jia extends YunSuan
{
function Suan()
{
return $this->a+$this->b;
}
}
class Jian extends YunSuan
{
function Suan()
{
return $this->a-$this->b;
}
}
class Cheng extends YunSuan
{
function Suan()
{
return $this->a*$this->b;
}
}
工厂类
class GongChang
{
给我一个参数,返回一个对象
static function ChanPin($name)
{
switch($name)
{
case "+":
return new Jia();
break;
case "-":
return new Jian();
break;
case "*":
return new Cheng();
break;
}
}
}
$a = GongChang::ChanPin("*");
var_dump($a);