Applied Design Patterns with Java

Creational :: Builder (97) {C ch 7}


Collaborations


The following interaction diagram illustrates how
Builder and Director cooperate with a client.



Consequences

The Builder pattern has these consequences:

  1. It lets you vary a product's internal representation. The Builder object provides the director with an abstract interface for constructing the product. The interface lets the Builder hide the internal structure of the product. To change the product's internal representation, simply define a new kind of Builder.
  2. It isolates code for construction and representation. The Builder pattern improves modularity by encapsulating the way a complex object is constructed and represented. Clients needn't know anything about the classes that define the product's internal structure; such classes don't appear in Builder's interface. Each ConcreteBuilder contains all the code to create and assemble a particular kind of product. The code is written once; then different Directors can reuse it to build Product variants from the same set of parts. This is exactly what is meant by the term 'Delegate'.
  3. It gives you finer control over the construction process. Unlike Creational Patterns that construct products in one shot, the Builder pattern constructs the product step by step under the director's control. Only when the product is finished does the director retrieve it from the Builder. Hence the Builder interface reflects the process of constructing the product more than other Creational Patterns. This allows finer control over the construction and internal structure of the resulting product.

Catalog Creational Prev Next