one questions about Builder Pattern
-
i have one questions about
Builder Pattern
..why we need product class where director class construct the component of product and when i want to produce any product i will implement IBuilder interface and write the behavior of each component and pass the concrete Builder to director without need the product and i will produce also different representation , plz give me the benefit of product class and real world example if u can ?Discover Other .... http://www.islamHouse.com
-
i have one questions about
Builder Pattern
..why we need product class where director class construct the component of product and when i want to produce any product i will implement IBuilder interface and write the behavior of each component and pass the concrete Builder to director without need the product and i will produce also different representation , plz give me the benefit of product class and real world example if u can ?Discover Other .... http://www.islamHouse.com
Builder pattern consists of 4 parts: 1. Builder-This is an abstract class 2. ConcreteBuilder 3. Director-This is the site where the construction occurs by calling the ConcreteBuilder 4. Product-This is the thing being built public class Demo { public static void main(String args[]) { Builder b = new ConcreteBuilder1(); Director d = new Director(); d.construct(b); // We tell director to construct a product using b as the builder and director // will call the appropriate methods on b. We do not need to know how the director // will do this, we assume the director knows this. Product aProduct = b.GetProduct(); // Now we ask b to give us the built product b = new ConcreteBuilder2(); d = new Director(); d.construct(b); Product anotherProduct = b.GetProduct()); } } Therefore, you need the product class because after all you are after the built product at the end. It is like going to a construction site and taking a builder with you. You ask the person in charge at the construction site (Director) to construct a house for you using the builder you introduced to the person in charge. The person in charge should know the sequence and what parts are needed to build a house but does not know how to build it. He simply asks the builder to build the parts. The builder now has a complete house. To see the completed house, you ask the builder for the house. I personally think we should ask the Director for the finished product as well and the director should ask the appropriate builder, but for some reason that is not the case.