p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional PHP Design Patterns (http://p2p.wrox.com/forumdisplay.php?f=513)
-   -   Qns regarding Builder Pattern example (http://p2p.wrox.com/showthread.php?t=77715)

restless January 8th, 2010 09:26 PM

Qns regarding Builder Pattern example
 
With reference to productBuilder class in page 35, i wonder what does the statement
Code:

$this->_xml = $configs;
do?

or should the build() method be

Code:

public function build(){
 $this->_product->setSize($this->_xml['size']);
 $this->_product->setType($this->_xml['type']);
 $this->_product->setColor($this->_xml['color']);
}

instead?

AaronSaray January 10th, 2010 01:59 PM

Hey - great catch. The example should be the following code:

PHP Code:

class productBuilder
{
    protected 
$_product NULL;
    protected 
$_configs = array();

    public function 
__construct($configs)
    {
        
$this->_product = new product();
        
$this->_configs $configs;
    }

    public function 
build()
    {
        
$this->_product->setSize($this->_configs['size']);
        
$this->_product->setType($this->_configs['type']);
        
$this->_product->setColor($this->_configs['color']);
    }

    public function 
getProduct()
    {
        return 
$this->_product;
    }


Sorry for any confusion. Thanks so much!


All times are GMT -4. The time now is 01:42 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.