#####PHP原型模式
/**
* Created by PhpStorm.
* User: gewenrui
* Date: 16/3/8
* Time: 下午3:18
*/
//设置一个接口 里面存放员工的属性
abstract class IAcmePrototype{
protected $name;
protected $id;
protected $employeePic;
protected $dept;
abstract function setDept($orgCode);
abstract function getDept();
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return mixed
*/
public function getEmployeePic()
{
return $this->employeePic;
}
/**
* @param mixed $employeePic
*/
public function setEmployeePic($employeePic)
{
$this->employeePic = $employeePic;
}
abstract function __clone();
}
class Marketing extends IAcmePrototype{
const UNIT = "Marketing";
private $sales = "sales";
private $promotion = "promotion";
private $strategic = "strategic planning";
public function setDept($orgCode)
{
switch($orgCode){
case 101:
$this->dept = $this->sales;
break;
case 102:
$this->dept = $this->promotion;
break;
case 103:
$this->dept = $this->strategic;
break;
default:
$this->dept = "fuck";
}
}
public function getDept()
{
// TODO: Implement getDept() method.
return $this->dept;
}
function __clone()
{
// TODO: Implement __clone() method.
}
}
class Management extends IAcmePrototype{
const UNIT = "Management";
private $research = "research";
private $plan = "planning";
private $operation = "operations";
public function setDept($orgCode)
{
switch($orgCode){
case 201:
$this->dept = $this->research;
break;
case 202:
$this->dept = $this->plan;
break;
case 203:
$this->dept = $this->operation;
break;
default:
$this->dept = "u Management";
}
// TODO: Implement setDept() method.
}
public function getDept()
{
return $this->dept;
// TODO: Implement getDept() method.
}
function __clone()
{
// TODO: Implement __clone() method.
}
}
class Engineering extends IAcmePrototype{
const UNIT = "Engineering";
private $development = "development";
private $design = "programming";
private $sysAd = "system administration";
public function setDept($orgCode)
{
switch($orgCode){
case 301:
$this->dept = $this->development;
break;
case 302:
$this->dept = $this->design;
break;
case 303:
$this->dept = $this->sysAd;
break;
default:
$this->dept = "ue";
}
// TODO: Implement setDept() method.
}
public function getDept()
{
return $this->dept;
// TODO: Implement getDept() method.
}
function __clone()
{
// TODO: Implement __clone() method.
}
}
class Client{
private $market;
private $manage;
private $engineer;
public function __construct()
{
$this->makeConProto();
//使用克隆模式来创建员工
$Tess = clone $this->market;
$this->setEmployee($Tess,"Tess smith",101,"ts101-1234","tess.pnbg");
$this->showEmployee($Tess);
$fucker = clone $this->manage;
$this->setEmployee($fucker,"shit",201,"sss","aaa");
$this->showEmployee($fucker);
}
public function makeConProto(){
$this->market = new Marketing();
$this->manage = new Management();
$this->engineer = new Engineering();
}
public function setEmployee(IAcmePrototype $employeeNow,$nm,$dp,$id,$px){
$employeeNow->setName($nm);
$employeeNow->setDept($dp);
$employeeNow->setId($id);
$employeeNow->setEmployeePic($px);
}
public function showEmployee(IAcmePrototype $employeeNow){
echo $px = $employeeNow->getEmployeePic()."";
echo $employeeNow->getName()."";
echo $employeeNow->getDept()."";
echo $employeeNow->getId()."";
}
}
$data = new Client();