都是deferring some implementation to subclass. Template多了点algorithm structure, 看了head first dp有点困惑。谢
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有点困惑。谢
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.
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.
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有点困惑。谢