例题:
//造父类
class YunSuan
{
public $a;
public $b;
function YunSuan()
{
}
}
//造加法的子类
class Jia extends YunSuan
{
function YunSuan()
{
return($this->a + $this->b);
}
}
//造减法的子类
class Jian extends YunSuan
{
function YunSuan()
{
return ($this->a - $this->b);
}
}
//造乘法的子类
class Cheng extends YunSuan
{
function YunSuan()
{
return ($this->a * $this->b);
}
}
//造除法的子类
class Chu extends YunSuan
{
function YunSuan()
{
return ($this->a / $this->b);
}
}
class GongChang
{
static function DuiXiang($a)
{
switch($a)
{
case "+":
return new Jia();
break;
case "-":
return new Jian();
break;
case "+":
return new Cheng();
break;
case "/":
return new Chu();
break;
}
}
}
$r = GongChang::DuiXiang("+");
$r->a =10;
$r->b =5;
echo $r->YunSuan();
ぉ 辰 プ 辰 ペ