|
整理:vcc |
1: 1107854 : ----------------------------------
*原文*(*dyingc*于2001/07/30 00:14粘贴) *有高手愿意谈谈Builder
Pattern和Abstract Factory Pattern之间的关系吗? *
---------------------------------------------------------------------------
这两个Pattern之间的关系似乎不太容易把握。书上说,Builer注重于步骤(construct step by
step);Abstract Factory注重于系列(families of product objects)。怎么理解?
---------------------------------------------------------------------------
2: 1107954 : ----------------------------------
*原文*(*gt7092b*于2001/07/31 08:04粘贴) *回复: 有高手愿意谈谈Builder
Pattern和Abstract Factory Pattern之间的关系吗? *
---------------------------------------------------------------------------
Personally, I think Abstract Factory is a factory for abstract
products. In particular, a group of abstractions. In contrast, Factory
Method creates one product. In such a sense, Abstract Factory usually
uses Factory Method to create individual products. One can use Singleton
in order to hide concrete factories.
Builder pattern is more interesting. First it intends to create complex
objects. Since the creation process might be complex as well, we need to
decompose the creation process. How to do it? It reminds me of two other
patterns: Template Method and Strategy. Note that in Template Method, it
is subclsses' responsibility to override primitive operations, whereas
in Builder I think all builders assume the role of providing varying
primitive operations. The director's construct() method assumes the role
of Template Method, which is the skelton of an algorithm. The individual
creation steps can be viewed as algorithms as well, so you might see
builders are strategies themselves. So, in my humble opinion, Builder is
a "creation strategy" for complex products.
cheers.
---------------------------------------------------------------------------
2: 1107917 : ----------------------------------
*原文*(*d_jt*于2001/07/30 16:01粘贴) *回复: Builder Pattern vs
Abstract Factory Pattern *
---------------------------------------------------------------------------
builder pattern 产品制造商角度或diy
builder pattern
用来制造产品的,你的角色相当于产品制造商,知道怎么用部件来制造产品,而部件来自部件制造商,你可以利用不同种类的部件,也可以用同种类的部件采用不同
的制造方法(可以生产三个轮子的汽车)
abstract factory 用户角度
从用户角度来考虑的,主要是给用户提供产品序列,用户可以方便的使用这些产品序列,但是用户没有可能去改变产品,只能使用已有的产品序列
例子:builder pattern 发烧友,经常diy
abstract factory 电脑菜鸟,只能买ibm,长城等系列品牌
---------------------------------------------------------------------------
2: 1107880 : ----------------------------------
*原文*(*bobgeng*于2001/07/30 11:18粘贴) *回复: 有高手愿意谈谈Builder
Pattern和Abstract Factory Pattern之间的关系吗? *
---------------------------------------------------------------------------
其实对于这两个pattern的区别最具有总结性的一句话应该是:Builder returns the product as a final
step,Abstract Factory returns the product immediately instead.
Builder强调的是整体是由部分组成的这个概念。比如你想要得到Car这个复杂对象,那你一定要先准备好Window,Door,Engine,Wh
eel等等这些构造Car所必须的简单对象,之后调用Builder的get操作得到Car这个最终产品;
而Abstract
Factory则并不强调这种关系,或者可以说是构造上的“松耦合”。拿一个GUI的例子来说,比如一个Window的Factory,你可以通过Fac
tory::CreateWindow接口马上得到一个简单的window对象,担这个window可能是没有任何修饰,比方说没有scrollbar等
等,but anyway,we have got a window immediately.
所以,Builder是一个step by step的构造过程,而Abstract Factory则是一个一步到位的构造过程。
---------------------------------------------------------------------------
3: 1107903 : ----------------------------------
*原文*(*dyingc*于2001/07/30 14:48粘贴) *回复: 有高手愿意谈谈Builder
Pattern和Abstract Factory Pattern之间的关系吗? *
---------------------------------------------------------------------------
你的意思是不是,constructor依次调用builder的buildPart方法,全部完成后再调用getResult方法得到整个produ
ct?那为什么不在builder中加一个construct方法,依次调用自己的buildPart方法呢?这样还可以减少constructor和b
uilder之间的耦合。
或者说,这种调用是运行时确定的,所以无法写在builder中?
---------------------------------------------------------------------------
4: 1107936 : ----------------------------------
*原文*(*bobgeng*于2001/07/30 18:21粘贴) *回复: 有高手愿意谈谈Builder
Pattern和Abstract Factory Pattern之间的关系吗? *
---------------------------------------------------------------------------
如果你将构造过程放在Builder里来作,那就失去的构造的灵活性。还拿Car来说,如果你在Builder里构造一种Car:一个门,一个窗子,一
个引擎;但是你又想构造另外一种,你绝对不愿意再修改你的Builder吧,所以Builder用来构造Part,而整体的结构就由另外的一个Direc
tor来得到。简单点来说,就是由你自己去组合这些零件,最后调用get method得到你要的product。
---------------------------------------------------------------------------
2: 1107866 : ----------------------------------
*原文*(*boss_ch*于2001/07/30 09:27粘贴) *回复: 有高手愿意谈谈Builder
Pattern和Abstract Factory Pattern之间的关系吗? *
---------------------------------------------------------------------------
我的理解 : 都是为了创新新的对象。主要在于两者的目标不同。 Abstract Factory
的主要目的,在于将具体的对象的类型给隐藏起来, 返回给使用者一个上层接口的对象 ,而不用去管具体的对象类型。
而 Builder pattern ,对于对象的构建过程有更精细的控制,其目的是将对象的构造过程(这个过程一般比较复杂,many steps
)独立出来,并且,用统一的方法,实现不同的构造。
个人理解 。
---------------------------------------------------------------------------
2: 1107856 : ----------------------------------
*原文*(*engineer2007*于2001/07/30 00:54粘贴) *回复: 有高手愿意谈谈Builder
Pattern和Abstract Factory Pattern之间的关系吗? *
---------------------------------------------------------------------------
你现在在么
---------------------------------------------------------------------------