F.Builder Pattern
Objective
Builder is used to build complex object step by step
Use builder when client application wants to construct the object of its own for example graphics editor or factory assembly line.
Class Diagram
Client or director (Client can be director too) holds an instance of Builder Interface and concrete actually build the product. Client (or director) is aware of construction logic.
Example and Uses
Menu Construction at run time
Production assembly line simulation.
Graphics Designer/GUI Designers
Special Considerations
Builder Vs Factory (Abstract Factory)
Technically builder uses factory pattern for object construction logic.
Abstract Factory emphasizes a family of product objects (either simple or complex).
If Client is aware of object construction logic then builder pattern should be used.
If client is not aware of object construction logic then use factory (Abstract Factory) pattern.
In the case of the Abstract Factory, the client uses the factory methods to create its own objects.
In the Builder case, the Builder class is instructed on how to create the object and then it is asked for it, but the way that the class is put together is up to the Builder class.
In practice the products created by the concrete builders have a structure significantly different. This also distinguishes the Builder pattern from the Abstract Factory pattern which creates objects derived from a common type.
Related Patterns
Builder can use one of the other patterns to implement which components are built. Abstract Factory, Builder, and Prototype can use Singleton in their implementations.
Builder often used to builds a Composite.
References