Builder Design Pattern - BEHIND JAVA

Builder Design Pattern

Share This

Purpose

Builder Design Pattern Separates the construction of a complex object from its representation so that the same construction process can create different representations

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

Parse a complex representation, create one of several targets.

Real World Example

The purpose of the builder pattern is to separate the construction of a complex object from its representation. so that the same construction process can create different representation.

Points to Remember

  • Decide if a common input and many possible representations (or outputs) is the problem at hand.
  • Encapsulate the parsing of the common input in a Reader class.
  • esign a standard protocol for creating all possible output representations. Capture the steps of this protocol in a Builder interface.
  • Define a Builder derived class for each target representation.
  • The client creates a Reader object and a Builder object, and registers the latter with the former.
  • The client asks the Reader to "construct".
  • The client asks the Builder to return the result.

Advanced Points

  • Sometimes creational patterns are complementary: Builder can use one of the other patterns to implement which components get built. Abstract Factory, Builder, and Prototype can use Singleton in their implementations.
  • Builder focuses on constructing a complex object step by step. Abstract Factory emphasizes a family of product objects (either simple or complex). Builder returns the product as a final step, but as far as the Abstract Factory is concerned, the product gets returned immediately.
  • Builder often builds a Composite.
  • Often, designs start out using Factory Method (less complicated, more customizable, subclasses proliferate) and evolve toward Abstract Factory, Prototype, or Builder (more flexible, more complex) as the designer discovers where more flexibility is needed.

No comments:

Post a Comment

Pages