设计模式_模版设计模式概述和使用
来源:互联网 发布:奥特曼皮套购买淘宝 编辑:程序博客网 时间:2024/05/28 19:23
模版设计模式概述模版方法模式就是定义一个算法的骨架,而将具体的算法延迟到子类中来实现优点使用模版方法模式,在定义算法骨架的同时,可以很灵活的实现具体的算法,满足用户灵活多变的需求缺点如果算法骨架有修改的话,则需要修改抽象类
package cn.itcast_01;public class GetTimeDemo {public static void main(String[] args) {// GetTime gt = new GetTime();// System.out.println(gt.getTime() + "毫秒");GetTime gt = new ForDemo();System.out.println(gt.getTime() + "毫秒");gt = new IODemo();System.out.println(gt.getTime() + "毫秒");}}
package cn.itcast_01;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;public abstract class GetTime {public long getTime() {long start = System.currentTimeMillis();// for循环// for (int x = 0; x < 100000; x++) {// System.out.println(x);// }// 视频// try {// BufferedInputStream bis = new BufferedInputStream(// new FileInputStream("a.avi"));// BufferedOutputStream bos = new BufferedOutputStream(// new FileOutputStream("b.avi"));// byte[] bys = new byte[1024];// int len = 0;// while ((len = bis.read(bys)) != -1) {// bos.write(bys, 0, len);// bos.flush();// }// bos.close();// bis.close();// } catch (IOException e) {// e.printStackTrace();// }// 再给测试代码:集合操作的,多线程操作的,常用API操作的等等...code();long end = System.currentTimeMillis();return end - start;}public abstract void code();}
package cn.itcast_01;public class ForDemo extends GetTime {@Overridepublic void code() {for (int x = 0; x < 100000; x++) {System.out.println(x);}}}
package cn.itcast_01;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;public class IODemo extends GetTime {@Overridepublic void code() {try {BufferedInputStream bis = new BufferedInputStream(new FileInputStream("a.avi"));BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("b.avi"));byte[] bys = new byte[1024];int len = 0;while ((len = bis.read(bys)) != -1) {bos.write(bys, 0, len);bos.flush();}bos.close();bis.close();} catch (IOException e) {e.printStackTrace();}}}
0 0
- 设计模式_模版设计模式概述和使用
- 设计模式-模版设计模式概述和使用-抽象类
- 设计模式_简单工厂模式概述和使用
- 设计模式_工厂方法模式的概述和使用)
- 设计模式_装饰模式概述和使用
- 设计模式之_模版设计模式
- 设计模式_设计模式的概述和分类
- 设计模式_模版方法模式
- 设计模式_设计模式概述(1)
- 设计模式--模版模式
- 设计模式--模版模式
- 黑马程序员_模版方法设计模式
- spring_HibernateTemplate(Hibernate模板)_模版设计模式
- Java设计模式_(行为型)_模版方法模式
- 设计模式--模版设计模式
- 设计模式系列之四_策略模式 和 模版方法模式(Template method)
- 设计模式_模版模式(Template Pattern)
- 设计模式-简单工厂模式概述和使用-接口
- post和get方法的区别
- Theme
- 梆定变量的长度不一致也可能会造成硬解析
- 京东2017实习校招笔试题目-异或实现
- 对象锁的同步与异步
- 设计模式_模版设计模式概述和使用
- 用ldd -r, c++filt, nm搞定一个so库缺符号的问题
- 5.参数传递
- AppTheme属性设置集合
- WebService应用以及jdk如何应用
- Linux之内存管理mm_struct
- socket实现http协议
- Undefined symbols for architecture i386: "register_all_MyClass(lua_State*)"
- error: QtGui/QAction: 没有那个文件或目录