复制代码 代码如下:
_type = $type;
}
public function setsize($size)
{
echo set product size
;
$this->_size = $size;
}
public function setcolor($color)
{
echo set product color
;
$this->_color = $color;
}
}
$config = array(
type=>shirt,
size=>xl,
color=>red,
);
// 没有使用bulider以前的处理
$oproduct = new product();
$oproduct->settype($config['type']);
$oproduct->setsize($config['size']);
$oproduct->setcolor($config['color']);
// 创建一个builder类
class productbuilder
{
var $_config = null;
var $_object = null;
public function productbuilder($config)
{
$this->_object = new product();
$this->_config = $config;
}
public function build()
{
echo --- in builder---
;
$this->_object->settype($this->_config['type']);
$this->_object->setsize($this->_config['size']);
$this->_object->setcolor($this->_config['color']);
}
public function getproduct()
{
return $this->_object;
}
}
$objbuilder = new productbuilder($config);
$objbuilder->build();
$objproduct = $objbuilder->getproduct();
以上就介绍了windowsbuilder php设计模式 builder建造者模式,包括了windowsbuilder方面的内容,希望对php教程有兴趣的朋友有所帮助。