首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Template Method Pattern 模板方法方式

2012-09-10 
Template Method Pattern 模板方法模式1. 简介?在一些方法中定义一个算法的骨架,而将一些步骤延迟到子类中

Template Method Pattern 模板方法模式

1. 简介

?

在一些方法中定义一个算法的骨架,而将一些步骤延迟到子类中。

模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤。

?

2.类图


Template Method Pattern 模板方法方式
?

3.实例

?

--摘自Junit的TestCase源码

?

......public abstract class TestCase extends Assert implements Test {......                /** * Runs the bare test sequence. * @exception Throwable if any exception is thrown */public void runBare() throws Throwable {setUp();try {runTest();}finally {tearDown();}}/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */protected void setUp() throws Exception {}/** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. */protected void tearDown() throws Exception {}......}

?

热点排行