由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - factory and abstract factory 的区别
相关主题
prototype和abstract factory的区别[合集] which design pattern is used if a static variable insid
design patterns到底有用吗?C++里最常用的design pattern都有哪些?
Is "Singleton" design pattern a type of "Factory method" de最常见的OO Design Pattern是什么啊? (转载)
How many people use design patterns when coding?有几个人能 背着把gof 23种pattern 用java 随便写5,6个写出来
有谁读过Design Patterns Explained: A New Perspective on Obj (转载)A question about singleton
求推荐讲OO Design的书工厂模式 (转载)
王垠:解密“设计模式”Design pattern reflecting context change
大部份 design pattern 是不需要的multithread program design pattern (C++)
相关话题的讨论汇总
话题: factory话题: abstract话题: singleton话题: 区别话题: string
进入Programming版参与讨论
1 (共1页)
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
11
面试的时候应该不会问这么深吧。
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.
1 (共1页)
进入Programming版参与讨论
相关主题
multithread program design pattern (C++)有谁读过Design Patterns Explained: A New Perspective on Obj (转载)
我老不厚道地说一句,C的工作稳定是假的。求推荐讲OO Design的书
问一下关于factory pattern对象的复制王垠:解密“设计模式”
两道Java面试问题大部份 design pattern 是不需要的
prototype和abstract factory的区别[合集] which design pattern is used if a static variable insid
design patterns到底有用吗?C++里最常用的design pattern都有哪些?
Is "Singleton" design pattern a type of "Factory method" de最常见的OO Design Pattern是什么啊? (转载)
How many people use design patterns when coding?有几个人能 背着把gof 23种pattern 用java 随便写5,6个写出来
相关话题的讨论汇总
话题: factory话题: abstract话题: singleton话题: 区别话题: string