Reference 1:http://en.wikipedia.org/wiki/builder_pattern
Reference 2:http://www.cnblogs.com/devinzhang/archive/2012/01/06/2314670.html
Builder mode executes and returns the result of a constructed object to a large number of constructors, step-by-step. The intent of the Builder design pattern is toseparate the construction of a complex object from its representation. B Y Doingso the same construction process can create different representations. The structure is as follows:
Builder : An interface that creates a large number of objects.
ConcreteBuilder : Implements the Builder class that returns the final Product .
Director : Get Builder and executes all constructs.
The following is illustrated in reference 2 as An example:
public interface Builder {void Buildparta (); void Buildpartb (); void Buildpartc (); ... Product GetResult (); } //Concrete Construction Tools public class ConcreteBuilder implements Builder {part parta, PartB, PARTC; public void Buildparta () {//Here is the code for how to build Parta}; public void Buildpartb () {//Here is the code for how to build PARTB}; public void Buildpartc () {//Here is how to build PARTB code}; public Product GetResult () {//return final assembly of finished product}; } //Builder public class Director {private builder builder; Public Director (Builder builder) {this.builder = builder; } public void construct () {Builder.buildparta (); BUILDER.BUILDPARTB (); BUILDER.BUILDPARTC (); ...... }} The instantiation of product depends on the various instantiation public of part interface product {}public Interfacepart {}
*******************************************************************************
Here's how to call Builder:
ConcreteBuilder builder = Newconcretebuilder () Director Director = new Director (builder); Director.construct (); Product Product = Builder.getresult ();
*******************************************************************************
The Director is responsible for performing the construction of the ConcreteBuilder, the advantage is the separation of the construction process. It is also possible for ConcreteBuilder to perform this build process by itself, removing the director, which is a simplified version of the builder pattern.
"Java class design pattern-02" builder mode (builder pattern)