Pattern: Builder

Synopsis

The Builder design pattern falls into the Creational design pattern category. Like the Factory design pattern, it abstracts the instantiation process. The critical distinction between the Builder and Factory patterns is that Builder is used to separate the representation of data and the construction logic of complex objects.

Context

We need to have a way to create objects that represent houses. We know that even though there are many different types of houses, they typically share common elements, e.g. doors, windows, roofs, etc.

How can we design an object that can serve as an object factory, but separate the creation of the object from the representation of the object? We use the Builder design pattern to solve this.

Forces

The considerations that lead one to use the Builder design pattern are as follows:

Solution

The Builder design pattern solves these problems by enforcing levels of delegation, and does so by providing he notion of "Clients," "Directors," and "Builders".

Consequences

Positive: Negative implications:

Implementation

Builder Design Pattern Demo.

Related Patterns


Modified: 19-Apr-2004
William Cava