工厂模式

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);
posted @ 2017-02-16 11:25  周全264  阅读(153)  评论(1编辑  收藏  举报