生产者设计模式与工厂设计模式有什么区别? [英] What is the difference between Builder Design pattern and Factory Design pattern?
问题描述
哪一个更有优势,为什么?
如果我想测试和比较/对比这些模式,我如何将我的发现作为图表?
使用设计模式,通常没有适用于所有情况的更有利的解决方案。这取决于你需要实现什么。
维基百科:
- Builder专注于逐步构建
复杂对象。抽象
工厂强调一系列产品
对象(简单或复杂)。
生成器将产品作为最终
步骤返回,但就抽象
工厂而言,产品立即获得
。
- Builder通常构建一个Composite。
- 通常,设计首先使用Factory Method(不太复杂,更多
可定制的子类增长)
并演变为抽象工厂
Prototype或者Builder(更灵活,
更复杂),因为设计师
发现需要更多的灵活性是
。
- 有时候创建模式是互补的:Builder可以使用一个
的其他模式来实现
哪些组件被构建。抽象
工厂,构建器和原型可以
在
实现中使用Singleton。
工厂设计模式的维基百科条目:
http://en.wikipedia .org / wiki / Factory_method_pattern
构建器设计模式的维基百科条目:
http://en.wikipedia.org/wiki/Builder_pattern
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 ?
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
这篇关于生产者设计模式与工厂设计模式有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!