一、需求分析
解决某类事情的步骤是固定的,此时我们可以为这类事情提供一个模版代码,从而提高效率
二、模式设计:
1.写出该类事情中的一件事情的解决方案(包括模版部分和变化部分)
2.将会发生变化的部分抽取出来成为一个方法,将其描述为抽象方法
3.使用final修饰模版方法,防止被重写
三、代码实现
用一个简单的小例子来说明:计算程序的执行时间
3.1 工具代码
abstract class CalRuntime{
public final void getTime(){
long startTime = System.currentTimeMillis(); //记录开始的时间
code();
long endTime = System.currentTimeMillis(); //记录结束的时间.
System.out.println("运行时间 :"+ (endTime-startTime));
}
public abstract void code();
}
3.2测试代码
class TestCal extends CalRuntime
{
public static void main(String[] args)
{
TestCal testCal = new TestCal();
testCal.getTime();
}
public void code(){
//your code
}
}
韩剧再婚皇后阿里云盘全集高清1080P资源链接-韩剧再婚皇后免费阿里云盘资源下载4K高清无删减版链接
poipiku网站如何打开-poipiku官网网页版访问入口
明日方舟:终末地-云游戏畅玩入口-明日方舟:终末地-网页版在线直连地址
poki在线小游戏网页版-poki免费游戏大全入口
poki游戏入口-点开即玩-poki游戏-在线免费畅玩
原神akt大佬资源viciNeko入口链接-原神akt大佬资源网页vicineko入口链接分享