should the builder reset its build environment after delivering the product

Posted by Sudhi on Stack Overflow See other posts from Stack Overflow or by Sudhi
Published on 2011-11-28T07:19:06Z Indexed on 2011/11/28 9:49 UTC
Read the original article Hit count: 295

Filed under:
|
|

I am implementing a builder where in the deliverable is retrieved by calling Builder::getProduct() . The director asks various parts to build Builder::buildPartA() , Builder::buildPartB() etc. in order to completely build the product.
My question is, once the product is delivered by the Builder by calling Builder::getProduct(), should it reset its environment (Builder::partA = NULL;, Builder::partB = NULL;) so that it is ready to build another product? (with same or different configuration?)

I ask this as I am using PHP wherein the objects are by default passed by reference (nope, I don't want to clone them, as one of their field is a Resource) . However, even if you think from a language agnostic point of view, should the Builder reset its build environment ? If your answer is 'it depends on the case' what use cases would justify reseting the environment (and other way round) ?

For the sake of providing code sample here's my Builder::gerProcessor() which shows what I mean by reseting the environment

/**
 * @see IBuilder::getProessor()
 */
public function getProcessor()
{
    if($this->_processor == NULL) {
        throw new LogicException('Processor not yet built!');
    } else {
        $retval = $this->_processor;
        $this->_product = NULL, $this->_processor = NULL;
    }
    return $retval;
}

© Stack Overflow or respective owner

Related posts about language-agnostic

Related posts about builder