Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits
Builder Print E-mail
User Rating: / 3
PoorBest 
Thursday, 20 January 2005 21:16
Separate the construction of a complex object from its representation so that the same construction process can create different representations.



Source Code

/**
 * The interface Product defines interface to create parts of the
 * Product.
 */
public interface Builder {

    /**
     * Construct part of the complex Product.
     */
    public void buildPart();

    /**
     * Construct the Product.
     *
     * @return the constructed product
     */
    public Product getProduct();
}

/**
 * The ConcreteBuilder is the product of a concrete builder.
 *
 */
public class ConcreteBuilder implements Product {
}


/**
 * The ConcreteBuilderBuilder creates and assembles parts of
 * the Product.
 *
 */
public class ConcreteBuilderBuilder implements Builder {

    /**
     * Reference to Product being constructed
     */
    private ConcreteBuilder concreteBuilder;

    /**
     * Construct part of the complex Product.
     */
    public void buildPart() {
        // put your code here
    }

    /**
     * Construct the Product.
     *
     * @return the constructed product
     */
    public Product getProduct() {
        return concreteBuilder;
    }
}


/**
 * The ConcreteBuilderClient initialized the Director with a
 * Concrete Bulder to create the Product and gets result from the Builder.
 *
 */
public class ConcreteBuilderClient {

    /**
     * Use the Builder to create the Product.
     */
    public void createProduct() {
        ConcreteBuilderBuilder builder = new ConcreteBuilderBuilder();
        new Director(builder).construct();
        Product product = builder.getProduct();
    }
}


/**
* The class Director manages Product creation using Builder.
*/
public class Director {

    /**
     * Reference to Builder currently used
     */
    private Builder builder;

    /**
     * Create a new Director instance.
     *
     * @param builder the builder which will create the product
     */
    public Director(Builder builder) {
        this.builder = builder;
    }

    /**
     * Construct the Product using the Builder.
     */
    public void construct() {
        builder.buildPart();
    }
}


/**
 * The interface Product defines a complex object that is
 * constructed part-by-part with Builder.

 */
public interface Product {
}






Tags See All Tags Add New Tag...

Please Enter New Tags Separated By Comma's
  Or Close

designpattern  java 
Powered By Joomla Tags

Comments
Add New Search RSS
It may have a copy-paste error in the sa
Guest (194.209.2.xxx) 2005-08-04 17:14:40

class Director is twice
and there isn't code for ConcreteBuilder
class

pamflexgrid (France)
----------
Corrected! thanks Cédric Walter

Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:):grin;)8):p:roll:eek:upset:zzz:sigh:?:cry
:(:x
Please input the anti-spam code that you can read in the image.

3.20 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Thursday, 04 August 2005 17:13 )
 
Content View Hits : 2926786

Enter Amount: