I am learning the Builder Pattern
In the above link (Java example), I noticed that the Builder offers interface to construct multiple components. Along with invoking them, we call the getProduct() as well.
The point I don't understand is that why does the Director need to call all those component-construct methods one by one and get the result in the end.
/** "Director" */
class Waiter {
private PizzaBuilder pizzaBuilder;
public void setPizzaBuilder(PizzaBuilder pb) { pizzaBuilder = pb; }
public Pizza getPizza() { return pizzaBuilder.getPizza(); }
public void constructPizza() {
pizzaBuilder.createNewPizzaProduct();
pizzaBuilder.buildDough(); // construct component 1
pizzaBuilder.buildSauce(); // construct component 2
pizzaBuilder.buildTopping(); // construct component 3
}
}
Why don't we include the code for constructing components 1, 2, 3 in the ConcreteBuilder class it self rather than in the Director, and in fact eliminate the Director layer.
I understand that the above approach might turn the Builder pattern into something else, but I don't get why the Director is doing the job step-by-step. What's the benefit? If there are multiple directors, there will be duplicate code, right? I might not be understanding the motive behind the execution of the Builder pattern...
UPDATE : Does the Builder pattern focus on offering customizable-component-selection while creating a larger complex object? Otherwise, as of now, I don't see the point in introducing an additional layer, the Director.
Even if that's the case, Decorator pattern might be a better idea to accomplish the same by dynamically customizing the components. Somewhere I'm missing the point behind the Builder.. :(