Saturday, April 01, 2006

builder pattern :

director
builder
product

requires a builder who builds a product from its parts
an abstract builder builds an abstract product with some abstract processes

The director is the one who determines the parts and the sequence in which the build processes are called to build a particular type of product.
ex:
class WorkShop {
//force the order of building process
public void construct(HouseBuilder hb) {
hb.buildFoundation();
hb.buildFrame();
hb.buildExterior();
hb.buildInterior();
}
}
When a new product is to be built, a new builder is created from the existing builder and it is used to build the new product. The advantage is as and when the new product emerges which changes only a specific part only the class / process which builds it can be modifiedand a new builder can be created so easily.

The client creates the Director object and configures it with the desired Builder object

Director notifies the builder whenever a part of the product should be built

Builder handles requests from the director and adds parts to the product

The client retrieves the product from the builder


ref:
http://www.javacamp.org/designPattern/
http://www.eli.sdsu.edu/courses/spring98/cs635/notes/builder/builder.html
http://unicoi.kennesaw.edu/~jbamford/csis4650/uml/GoF_Patterns/builder.htm

No comments: