On the one hand, factory method is concerned about what is made but the builder pattern is concerned about how to make.
A builder pattern implementation will have:
1)an abstract builder
2)some concrete builders
3)a director
4)a product/object
5)a requester
The requester uses the director to build the product/object.
The builder constructs the product/object in phases by using the concrete builder as specified by the requester and returns it back.
The concrete builders extend the abstract builder.
e.g.
A builder pattern implementation will have:
1)an abstract builder
2)some concrete builders
3)a director
4)a product/object
5)a requester
The requester uses the director to build the product/object.
The builder constructs the product/object in phases by using the concrete builder as specified by the requester and returns it back.
The concrete builders extend the abstract builder.
e.g.
//Product
class Product {
setthis()
setthat()
}
//Abstract builder
abstract class ProductBuilder{
createnewproduct{
product = new Procuct();
}
getProduct{
return product
}
abstract dothis()
abstract dothat()
}
//concretebuilder
class StrangeProductBuilder extends ProductBuilder{
dothis()
dothat()
}
//concretebuilder
class AmazigProductBuilder extends ProductBuilder{
dothis()
dothat(0
}
//director. It calls the product's dothis() dothat() methods
class ProductDirector{
private ProductBuilder;
setProductBuilder(ProductBuilder pb){
ProductBuilder = pb;
}
constructProduct() {
//intantiate and call dothis and do that
}
getProduct() {
return ProductBuilder.getProduct(); //see Product Builder above for getProduct()
}
}
//requester
class requester{
ProductDirector pd = new ProductDirector();
ProductBuilder stProduct = new StrangeProductBuilder();
pd.setProductBuilder(stProduct );
pd.constructProduct()
Product p = builder.getProduct()
}
0 Comments On This Entry
← January 2022 →
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 | 31 |
My Blog Links
Recent Entries
-
-
-
SCJP Notes - Part 6on Mar 27 2008 08:19 AM
-
SCJP Notes - Part 5on Mar 27 2008 08:05 AM
-
Recent Comments
Search My Blog
6 user(s) viewing
6 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)



Leave Comment









|