- 浏览: 118651 次
- 性别:
- 来自: 大连
-
文章分类
最新评论
-
ccfangle:
bestchenwu 写道什么时候用“==”还是“equals ...
操作符“==”与对象的equals()方法 -
bestchenwu:
什么时候用“==”还是“equals()”,跟你是把这个对象作 ...
操作符“==”与对象的equals()方法
An application framework allows you to inherit from a class or set of classes and create a new application, reusing most of the code in the existing classes and overriding one or more methods in order to customize the application to your needs. A fundamental concept in the application framework is the Template Method which is typically hidden beneath the covers and drives the application by calling the various methods in the base class (some of which you have overridden in order to create the application).
For example, whenever you create an applet you’re using an application framework: you inherit from JApplet and then override init( ) . The applet mechanism (which is a Template Method ) does the rest by drawing the screen, handling the event loop, resizing, etc.
An important characteristic of the Template Method is that it is defined in the base class and cannot be changed. It’s sometimes a private method but it’s virtually always final . It calls other base-class methods (the ones you override) in order to do its job, but it is usually called only as part of an initialization process (and thus the client programmer isn’t necessarily able to call it directly).
//: templatemethod:TemplateMethod.java
// Simple demonstration of Template Method.
package templatemethod;
import junit.framework.*;
abstract class ApplicationFramework {
public ApplicationFramework() {
templateMethod(); // Dangerous!
}
abstract void customize1();
abstract void customize2();
final void templateMethod() {
for(int i = 0; i < 5; i++) {
customize1();
customize2();
}
}
}
// Create a new "application":
class MyApp extends ApplicationFramework {
void customize1() {
System.out.print("Hello ");
}
void customize2() {
System.out.println("World!");
}
}
public class TemplateMethod extends TestCase {
MyApp app = new MyApp();
public void test() {
// The MyApp constructor does all the work.
// This just makes sure it will complete
// without throwing an exception.
}
public static void main(String args[]) {
junit.textui.TestRunner.run(TemplateMethod.class);
}
} ///:~
The base-class constructor is responsible for performing the necessary initialization and then starting the “engine” (the template method) that runs the application (in a GUI application, this “engine” would be the main event loop). The client programmer simply provides definitions for customize1( ) and customize2( ) and the “application” is ready to run.
//上面的例子比较简单,很容易就能看明白,在时间当中可就没有那么容易。主要是体现在抽象函数的复杂性。我接触过的和能想到的实际应用就是:
<1> Servlet开发,只用你extends HttpServlet ,覆盖其中的doGet(),doPost()方法就好了。具体servlet的调用是由web服务器来完成的(服务器应用Template Method 模式隐藏了具体的数据连接、传输的过程,比如Socket连接等,这个只要稍微看看Tomcate的初始源码就可以了解了),只要你在自己实现函数中,将业务处理部分添加,然后,将实现类在web.xml中配置好就OK了,这个是一个很典型的应用;
<2> 此外就是JDBC中,jdbcTemplate开源应用中,应用的Template Method模式,就连接数据库,或者是启用数据源的应用部分封装在模板类中,而将具体的查询类接口通过DAO设计模式,暴露出来,同样,这个应用也是很典型的!
发表评论
-
25-设计模式学习总结
2012-02-06 15:42 1050在学习Thinking in patterns之前 ... -
24-Prototype
2012-02-06 14:56 926Prototype(原型模式):用原型实例指定创建 ... -
23-Interpreter
2012-02-05 14:51 955If the application user n ... -
22-Visitor
2012-02-05 11:12 898The assumption is that yo ... -
21-Memento
2012-02-03 17:57 973Use serialization to crea ... -
20-Chain of responsibility
2012-02-03 16:25 1000Chain of Responsibility ... -
19-Command: choosing the operation at run-time
2012-02-01 17:45 991A Command is a function o ... -
18-Facade
2012-01-15 15:22 952Facade模式 : 为子系统中的一组接口提供一个一致的 ... -
17-Mediator
2012-01-14 19:40 893Mediator模式:用一个中介对象来封装一系列 ... -
16-Observer
2012-01-12 21:35 801好久之前看过Observer,但是,当时不是很清楚 ... -
15-Composite
2012-01-12 10:11 921Composite模式,有时又叫做部分-整体模式(Pa ... -
14-Bridge
2012-01-11 17:06 871思考了好一阵,总 ... -
13-Adapter
2012-01-10 21:38 830接下来的两个模式目的就是:Connecting differe ... -
12-Decorator:too many classes
2012-01-06 20:17 1012呵,从翻译这 ... -
11-Flyweight: too many objects
2012-01-06 16:10 982The odd thing about flyweight, ... -
10-Builder
2012-01-06 09:14 857The goal of builder is to separ ... -
9-Factory method(Simple Factory method&Abstract factories)
2012-01-03 19:16 890//工厂方法的理解比较容易,重要还是如何在实践中应用。以下范例 ... -
7-Policy: generalized strategy
2012-01-01 15:58 1178Although GoF says that Policy i ... -
6-Strategy: choosing the algorithm at run-time
2011-12-29 10:40 1070Strategy : choosing the alg ... -
5-Iterators: decoupling algorithms from containers
2011-12-27 15:39 957In the process, he realized th ...
相关推荐
scratch少儿编程逻辑思维游戏源码-上下飞行.zip
kkzhilu_Code-Generate_32152_1745864907745
艺术博客_SpringSpringMVCMybatisShirojQueryBootstrapechartswebuploaderlayui_博客管理图表数据日
scratch少儿编程逻辑思维游戏源码-面具古墓.zip
scratch少儿编程逻辑思维游戏源码-时钟上的冰块.zip
健康监测_Android开发_BLE蓝牙通信_心率数据采集与存储_基于小米手环2的实时心率监测应用_支持后台长时间运行的心率记录工具_可导出SQLite数据库的心率数据分析系统_适
scratch少儿编程逻辑思维游戏源码-梦魇忍者.zip
scratch少儿编程逻辑思维游戏源码-谁建得更高.zip
scratch少儿编程逻辑思维游戏源码-忍者攀登.zip
模拟端 后端 qt前端
数据可视化_Android原生Canvas绘图_3D与非3D柱形图饼图折线图面积图曲线图环形图玫瑰图雷达图散点图气泡图仪表盘刻度盘漏斗图象限图_支持手势缩放滑动交互多图叠加动画效果
scratch少儿编程逻辑思维游戏源码-米克 demo.zip
聚合支付系统/官方个人免签系统/三方支付系统稳定安全高并发 附教程 系统采用FastAdmin框架独立全新开发,安全稳定,系统支持代理、商户、码商等业务逻辑。 针对最近一些JD,TB等业务定制,子账号业务逻辑API 非常详细,方便内置对接! IP白名单 业务逻辑 支持IP白名单,黑名单,全局白名单,全局黑名单,保障系统的安全。 接口验签名 采用支付宝RSA加密接口方式,防止篡改数据,导致对账困难,资金大量损失,无故少钱 对接灵活 全部对接参数灵活操作 风控完善 轮询、交易金额、随机金额、最大金额、最小金额等 测试环境: Nginx+PHP7.0+MySQL5.6 网站运行目录:/public 伪静态设置为:thinkphp规则 数据库信息修改路径:/application/database.php
第一步 package.json 下载这三个包 shelljs :执行 shell命令 ssh2-sftp-client 与服务器建立链接(内部有ssh2) chalk 打印彩色输出 第二步 配置脚本命令 deploy 注意后边加上运行环境 执行deploy命令时内部执行了打包动作 「 "deploy": "node deploy/index.js --prod」 第三步准备服务器密码 账号 部署地址 备份地址等等 参考如下 放到 config.js 中 module.exports = [ { id: 0, nodeEnv: "prod", name: "正式环境", domain: "", host: "ip", port: 端口, username: "用户名", password: "密码", path: "/data/www/paccount",//部署路径 removepath: "/data/www/paccount", //删除路径 }, ]; 第四步 如果需要在服务器执行命令 在部署完成后执行 chmodDir 自行决定
scratch少儿编程逻辑思维游戏源码-恐怖矿井.zip
scratch少儿编程逻辑思维游戏源码-爬墙鸟.zip
scratch少儿编程逻辑思维游戏源码-亮灯.zip
scratch少儿编程逻辑思维游戏源码-神秘的游戏.zip
scratch少儿编程逻辑思维游戏源码-矿猫 V4.zip
scratch少儿编程逻辑思维游戏源码-射击游戏构建.zip