1.Topics‎ > ‎Architecture‎ > ‎Patterns‎ > ‎a.Design Patterns‎ > ‎B.Creational Patterns‎ > ‎

F.Builder Pattern

  1. Objective
    1. Builder is used to build complex object step by step
    2. Use builder when client application wants to construct the object of its own for example graphics editor or factory assembly line.
  2. Class Diagram
    1. 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.

  3. Example and Uses
    1. Menu Construction at run time 
    2. Production assembly line simulation.
    3. Graphics Designer/GUI Designers
  4. Special Considerations
    1. Builder Vs Factory (Abstract Factory)
      1. Technically builder uses factory pattern for object construction logic.
      2.  Abstract Factory emphasizes a family of product objects (either simple or complex).
      3. If Client is aware of object construction logic then builder pattern should be used.
      4. If client is not aware of object construction logic then use factory (Abstract Factory) pattern.
      5. In the case of the Abstract Factory, the client uses the factory methods to create its own objects.
      6. 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.
      7. 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. 
    2. Related Patterns 
      1. 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.
      2.  Builder often used to builds a Composite.
  5. References 
    1. http://www.oodesign.com/builder-pattern.html