任何人都可以让我知道应该使用模板方法 - 模式的一些示例情况?
从我们自己的经验中给我一些现实世界的使用。 >
(到目前为止,我发现它只对DA层中的数据进行映射有用。对不起!!!)
解决方案模板方法模式为执行任何类型的算法或操作提供了一个框架,它允许子类重新定义部分逻辑。 / p>
优点:自然适合构建框架,以便父框架类可以使回调到子程序中实现的方法。
示例:
- java.util.AbstractList
- Servlet的doGet和doPost方法
- MDB的onMessage方法
- Struts Action类
- Spring的数据访问clas ses
缺点:限制您在Java中的单一继承。
Can anyone let me know some example situations where Template Method - pattern should be used?
Give me some real-world use from your own experience.
(I have so far found it useful only for mapping data in the DA layer. Sorry!!!)
解决方案A Template method pattern provides a skeleton for performing any sort of algorithm or an operation, and it allows the sub-classes to re-define part of the logic.
Pros: Natural fit for building frameworks, so that parent framework classes can make callbacks into methods implemented in child.
Examples:
- java.util.AbstractList
- Servlet's doGet and doPost methods
- MDB's onMessage method
- Struts Action class
- Spring's data access classes
Cons: Restricts you to a single inheritance in Java.
更多推荐
我们应该在哪里使用模板方法
发布评论