php企业项目原型,PHP原型模式

#####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();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值