Builder Pattern

The gof.gif (158 bytes) Builder Pattern separates the construction of a complex object from its representation so that the same construction process can create different representations.

Wizard
Applicability
Additional Resources

Wizard

Option Description Default
Source folder Enter a source folder for the new class. Either type a valid source folder path or click Browse to select a source folder via a dialog. The source folder of the element that was selected when the wizard was started.
Package Enter a package to contain the new class. Either type a valid package name or click Browse to select a package via a dialog. The package of the element that was selected when the wizard has been started.
Builder interface Type or click Browse to select the builder interface <Builder>
Build part method Type or select the name of the method that will construct parts of bthe product <buildPart>
Get product method Type or select the name of the method that will return the constructed product <getProduct>
Director class Type a name for the new director class. <Director>
Modifiers Select one or more access modifiers for the new class.
  • public (uncheck for default visibility)
  • abstract
  • final
public
Superclass Type or click Browse to select a superclass for this class. <java.lang.Object>
Builder field Type or select the name of the field that will contain the instance of the builder class <builder>
Construct method Type or select the name of the method that will be called to construct the product <construct>
Product interface Type or click Browse to select the product interface <Product>
Product classes Click Add to enter the names of the product classes that should be created <blank>
Create concrete builder classes for each product Determines whether the builder classes should be created for each product <true>

Applicability

Use the Builder pattern when

  • the algorithm for creating a complex object should be independent of the parts that make up the object and how they're assembled.
  • the construction process must allow different representations for the object that's constructed.

Additional Resources

http://c2.com/cgi/wiki?BuilderPattern

http://www.wikipedia.org/wiki/Builder_pattern

http://www.cmcrossroads.com/bradapp/javapats.html#Builder

http://www.dofactory.com/patterns/pattern_builder.asp

http://www.castle-cadenza.demon.co.uk/builder.htm