现在的位置: 首页 > 综合 > 正文

Builder

2013年10月25日 ⁄ 综合 ⁄ 共 1664字 ⁄ 字号 评论关闭

The Builder Pattern

is a software design pattern
.
The intention is to abstract steps of construction of objects so that
different implementations of these steps can construct different
representations of objects.

Often, the Builder Pattern

is used to build Products in accordance to the Composite pattern
, a structure pattern.

 

 

Class Diagram

Builder Structure

 

 

Useful tips

  • 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.
  • Sometimes creational patterns are complementary: 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.

 

Consequences of the Builder Pattern

  • A Builder lets you vary the internal representation of the product it builds. It also hides the details of how the product is assembled.
  • Each specific builder is independent of the others and of the rest of the program. This improves modularity and makes the addition of other builders relatively simple.
  • Because each builder constructs the final product step-by-step, depending on the data, you have more control over each final product that a Builder constructs.
  • A Builder pattern is somewhat like an Abstract Factory pattern in that both return classes made up of a number of methods and objects. The main difference is that while the Abstract Factory returns a family of related classes, the Builder constructs a complex object step by step depending on the data presented to it.

抱歉!评论已关闭.