t******m 发帖数: 255 | 1 那位大侠能不能给解释下factory 和 abstract factory到底有啥区别呀?看了半天书
,都不明白。谢谢先! |
g*****g 发帖数: 34805 | 2 Abstract Factory returns Factory.
Think of a UI that can use different look and feel on different OS.
You specify look and feel to get the factory from abstract factory,
then use the factory to get the components.
Java Swing is kind of like that, although it doesn't exactly use
factory to get components.
【在 t******m 的大作中提到】 : 那位大侠能不能给解释下factory 和 abstract factory到底有啥区别呀?看了半天书 : ,都不明白。谢谢先!
|
z****e 发帖数: 2024 | 3 如果是factory返回factory自己的话,
是不是factory最好是singleton的?
【在 g*****g 的大作中提到】 : Abstract Factory returns Factory. : Think of a UI that can use different look and feel on different OS. : You specify look and feel to get the factory from abstract factory, : then use the factory to get the components. : Java Swing is kind of like that, although it doesn't exactly use : factory to get components.
|
X****r 发帖数: 3557 | 4 什么叫factory返回factory自己?你是说factory返回另一个factory?
【在 z****e 的大作中提到】 : 如果是factory返回factory自己的话, : 是不是factory最好是singleton的?
|
z****e 发帖数: 2024 | 5 就是factory自己是一个singleton结构,
然后每次需要产生一个新对象,就call factory's static member function to
retrieve the unique factory object.
【在 X****r 的大作中提到】 : 什么叫factory返回factory自己?你是说factory返回另一个factory?
|
z****e 发帖数: 2024 | 6 for example, given a string, how to generate an object which type is
described by the string?
i think a singleton factory could be used.
first, we can register the types corresponding to the string and this can be
done by using the unique factory object. so even new string is added, the
old ones won't mess up.
since there is only one factory object, it will alway generate the correct
type.
【在 X****r 的大作中提到】 : 什么叫factory返回factory自己?你是说factory返回另一个factory?
|
X****r 发帖数: 3557 | 7 你当然可以用singleton factory,但是我看不出你这里描述的有任何
“factory返回factory自己”,也没abstract factory什么事啊。
can be
the
correct
【在 z****e 的大作中提到】 : for example, given a string, how to generate an object which type is : described by the string? : i think a singleton factory could be used. : first, we can register the types corresponding to the string and this can be : done by using the unique factory object. so even new string is added, the : old ones won't mess up. : since there is only one factory object, it will alway generate the correct : type.
|
z****e 发帖数: 2024 | 8 哦,我其实是问问 abstract factory 和一个singleton 的factory,是不是一起用?
【在 X****r 的大作中提到】 : 你当然可以用singleton factory,但是我看不出你这里描述的有任何 : “factory返回factory自己”,也没abstract factory什么事啊。 : : can be : the : correct
|
X****r 发帖数: 3557 | 9 abstract factory本身当然可以是singleton的。
abstract factory所返回的factory,在实现上对于某一种具体的类别的可以是
singleton,比如在goodbug的例子里,如果客户要求Windows 3.1下的look & feel,
那这个被返回的factory就可以总是同一个对象。但是这个singleton的实现对客户不应该
是直接可见的。
【在 z****e 的大作中提到】 : 哦,我其实是问问 abstract factory 和一个singleton 的factory,是不是一起用?
|
g*****g 发帖数: 34805 | 10 Factory/abstract factory倒是经常跟singleton一起用,但不是必须。
【在 z****e 的大作中提到】 : 哦,我其实是问问 abstract factory 和一个singleton 的factory,是不是一起用?
|
z****e 发帖数: 2024 | |
k**3 发帖数: 917 | 12 Among GoF patterns, there are Abstract Factory and Factory Method patterns,
but no Factory pattern.
Abstract Factory creates a "family" of "abstract" products.
Factory Method is about letting subclasses decide what concrete products to
create.
In practice, Factory can be considered as a special case of Abstract Factory
, which creates only one product, abstract or concrete, but abstract
preferred. |