建造者设计模式和工厂设计模式有什么区别? [英] What is the difference between Builder Design pattern and Factory Design pattern?
问题描述
Builder 设计模式和 Factory 设计模式有什么区别?
What is the difference between the Builder design pattern and the Factory design pattern?
哪个更有利,为什么?
如果我想测试和比较/对比这些模式,如何将我的发现表示为图表?
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.
来自维基百科:
- Builder 专注于构建一个复杂的对象一步一步.抽象的工厂强调产品家族对象(简单的或复杂的).Builder 将产品作为最终产品返回步骤,但就摘要而言工厂而言,产品得到立即返回.
- Builder 经常构建一个 Composite.
- 通常,设计开始时使用工厂方法(不那么复杂,更多可定制,子类激增)并向抽象工厂演进,原型或构建器(更灵活,更复杂)作为设计师发现更大的灵活性在哪里需要.
- 有时创建模式是互补的:Builder 可以使用一个要实现的其他模式构建了哪些组件.抽象的Factory、Builder 和 Prototype 可以在他们的使用单例实施.
工厂设计模式的维基百科条目:http://en.wikipedia.org/wiki/Factory_method_pattern
Wikipedia entry for factory design pattern: http://en.wikipedia.org/wiki/Factory_method_pattern
构建器设计模式的维基百科条目:http://en.wikipedia.org/wiki/Builder_pattern
Wikipedia entry for builder design pattern: http://en.wikipedia.org/wiki/Builder_pattern
这篇关于建造者设计模式和工厂设计模式有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!