由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请教template和factory有啥区别?
相关主题
C++ template problemHow does YAHOO calculate RSI? (转载)
两个看来相似的问题内存池这个玩意...
Help C++ Template function link error .map是用什么data structure来implement的?
Question in C++ complex number implementation一个STL的问题
一个 C++ STL base type 的问题人无食不活,码无库不通
两道Java面试问题[合集] Exception Handling in C
good C++ open source project?C++ Singleton Help
网络程序问题If using C++, please avoid the use of STL for these questio (转载)
相关话题的讨论汇总
话题: template话题: factory话题: pattern话题: subclass话题: deferring
进入Programming版参与讨论
1 (共1页)
g***p
发帖数: 139
1
都是deferring some implementation to subclass.
Template多了点algorithm structure,
看了head first dp有点困惑。谢
g*****g
发帖数: 34805
2
factory stresses on interface, you have the same interface and pluggable
implementations, thus caller can be unaware of implementation.
Example, DB driver, you want to use one new DB, you have to have a new
driver
that implements the interface.
template stress on using same operation on different data type.
You are implementing a generic operation, most useful for collection
opertations like insert/delete/sort in STL.

【在 g***p 的大作中提到】
: 都是deferring some implementation to subclass.
: Template多了点algorithm structure,
: 看了head first dp有点困惑。谢

g***p
发帖数: 139
3
fatory - subclass decide which concrete class to create.
template - use delegation decide which behavior to use
nod. 每个pattern都不难理解,放在一起就有点晕。

【在 g*****g 的大作中提到】
: factory stresses on interface, you have the same interface and pluggable
: implementations, thus caller can be unaware of implementation.
: Example, DB driver, you want to use one new DB, you have to have a new
: driver
: that implements the interface.
: template stress on using same operation on different data type.
: You are implementing a generic operation, most useful for collection
: opertations like insert/delete/sort in STL.

L*********r
发帖数: 92
4
factory method pattern: it is a creational pattern. it is used to seperate
the class instantiation from the caller. so the caller can get the object
instance without know or refer to the concrete class.
template method pattern: it is a behavior pattern. it defines the skeleton
of business logic in the abstract class. the subclass implements the
business logic following the skeleton.
m******t
发帖数: 2416
5

Almost all the design patterns are about deferring/delegating something to
somebody else. It is the "why" and "how" that make them different.

【在 g***p 的大作中提到】
: 都是deferring some implementation to subclass.
: Template多了点algorithm structure,
: 看了head first dp有点困惑。谢

O*******d
发帖数: 20343
6
template是C++语言的一部分, factory不是。
m******t
发帖数: 2416
7

This "template" is not that "template". 8-)

【在 O*******d 的大作中提到】
: template是C++语言的一部分, factory不是。
q****m
发帖数: 153
8
haha

【在 O*******d 的大作中提到】
: template是C++语言的一部分, factory不是。
1 (共1页)
进入Programming版参与讨论
相关主题
If using C++, please avoid the use of STL for these questio (转载)一个 C++ STL base type 的问题
如何比较C, C++ 和JAVA???两道Java面试问题
A C++ inheritance question!good C++ open source project?
friend function in C++网络程序问题
C++ template problemHow does YAHOO calculate RSI? (转载)
两个看来相似的问题内存池这个玩意...
Help C++ Template function link error .map是用什么data structure来implement的?
Question in C++ complex number implementation一个STL的问题
相关话题的讨论汇总
话题: template话题: factory话题: pattern话题: subclass话题: deferring