class Builder
{
protected $product;
public function getProduct()
{
return $this->product;
}
public function buildProduct()
{
$this->product = new Product();
}
public function buildPartA()
{
$this->product->setPartA('Part A');
}
public function buildPartB()
{
$this->product->setPartB('Part B');
}
public function buildPartC()
{
$this->product->setPartC('Part C');
}
}
class Director
{
public function build(Builder $builder)
{
$builder->buildProduct();
$builder->buildPartA();
$builder->buildPartB();
$builder->buildPartC();
}
}
$builder = new Builder();
$director = new Director();
$director->build($builder);
$product = $builder->getProduct();
PHP代码实现建造者模式
最新推荐文章于 2024-08-16 19:46:43 发布