With design patterns, there usually is no "more advantageous" solution that works for all cases. It depends on what you need to implement.
From Wikipedia:
- 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 get built. Abstract
Factory, Builder, and Prototype can
use Singleton in their
implementations.
Wikipedia entry for factory design pattern:
http://en.wikipedia.org/wiki/Factory_method_pattern
Wikipedia entry for builder design pattern:
http://en.wikipedia.org/wiki/Builder_pattern
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…