Builder

Intent

Separate the construction of a complex object from its representation so that the same construction process can create different representations.

builders

Solution

You obtain a target class, which you need to use in your designs, but, the public interface of the target class (it’s methods) does not match your requirements or it does not fit into the necessary class inheritance hierarchy.

Solution

  1. Create an abstract Builder class which implements BuildPart (FactoryMethod) functions to build each type of component part.

  2. ConcreteBuilder subclasses implement the FactoryMethods as required.

  3. The Director class calls the BuildPart functions in Builder to request construction of each component part and then returns the entire complex object structure to its client.

Consequences

Related Patterns


Quick Pick