What is the difference between the Builder design pattern and the Factory design pattern?
Which one is more advantageous and why ?
How do I represent my findings as a graph if I want to test and compare/contrast these patterns ?
Answer
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
No comments:
Post a Comment