Design Patterns Explained
  • Getting Started
  • SOLID Principles
    • Single Responsibility Principle
    • Open / Closed Principle
    • Liskov Substitution Principle
    • Interface Segregation Principle
    • Dependency Inversion Principle
  • Design Patterns
    • Creational Patterns
      • Abstract Factory Pattern
      • Builder Pattern
      • Factory Pattern
      • Prototype Pattern
      • Singleton Pattern
    • Behavioral Patterns
      • Chain Of Responsibility Pattern
      • Command Pattern
      • Interpreter Pattern
      • Iterator Pattern
      • Mediator Pattern
        • Example 1
      • Memento Pattern
      • Observer Pattern
      • State Pattern
      • Strategy Pattern
        • Example 1
      • Template Method Pattern
      • Visitor Pattern
    • Structural Patterns
      • Adapter Pattern
      • Bridge Pattern
      • Composite Pattern
      • Decorator Pattern
      • Facade Pattern
      • Flyweight Pattern
      • Proxy Pattern
  • Roadmap
Powered by GitBook
On this page
  • When to use
  • Structure
  • Examples

Was this helpful?

  1. Design Patterns
  2. Creational Patterns

Builder Pattern

PreviousAbstract Factory PatternNextFactory Pattern

Last updated 4 years ago

Was this helpful?

Separates the construction of a complex object from its representation, as that the same construction process can create different representations.

When to use

  1. The algorithm for creating a complex object should be independent of the parts that make up the object and how they're assembled.

  2. The construction process must allow different representations for the object that's constructed.

  3. You want to get rid of a "telescopic constructor".

Structure

  • Builder: defines the interface for creating parts of a product object.

  • ConcreteBuilder: constructs and assembles parts of the product by implementing the Builder interface, also keeps track of the representation it creates, and provides an interface to retrieve it.

  • Director: constructs an object using the builder interface.

  • Product: represents the complex object under construction.

Examples

Source Code

UML

// TODO

You can find the tests .

here
Example 1