Redian新闻
>
请教template和factory有啥区别?
avatar
请教template和factory有啥区别?# Programming - 葵花宝典
g*p
1
都是deferring some implementation to subclass.
Template多了点algorithm structure,
看了head first dp有点困惑。谢
avatar
g*g
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有点困惑。谢

avatar
g*p
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.

avatar
L*r
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.
avatar
m*t
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有点困惑。谢

avatar
O*d
6
template是C++语言的一部分, factory不是。
avatar
m*t
7

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

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

【在 O*******d 的大作中提到】
: template是C++语言的一部分, factory不是。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。