JAVA模板方法模式
模板方法模式的结构
模板方法模式是所有模式中最为常见的几个模式之一,是基于继承的代码复用的基本技术。
模板方法模式需要开发抽象类和具体子类的设计师之间的协作。一个设计师负责给出一个算法的轮廓和骨架,另一些设计师则负责给出这个算法的各个逻辑步骤。代表这些具体逻辑步骤的方法称做基本方法(primitive method);而将这些基本方法汇总起来的方法叫做模板方法(template method),这个设计模式的名字就是从此而来。
模板方法所代表的行为称为顶级行为,其逻辑称为顶级逻辑。模板方法模式的静态结构图如下所示:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAAERCAIAAAAPKifHAAAZqklEQVR4nO2dMZKsNheFJ5qqP5tNUPXCCV9A4NApO3CVtkDwNkB5A8odsAIih4ROyF1sAIcOCBzqD071rfskQUM3Glrd54t6GLW4SKelK7jovjlCcuPtbAMI2Q1VS/KDqiX5QdWS/KBqSX5QtSQ/dqj28/PzjZCj+fz8TKjatzcOzOR4btAVVUtOhqol+UHVkvygakl+ULUkP15FteM4zvMsf07T1Pf9eeZ8NeM4tm17thWH8RKqnaapKAqR6TzPVVU1TXOqUT7DMJRl2TRNURR1XRtjDrFwnuemaaqqKsvy/toehJdQbdu2ZVnWdS1HmqbZpQn93aPo+34YBvnTWovfVVEUOG6MOepcTdNsVK1n1WPyEqrFuKW7bZdq53mOdvk0TXdapfUhDoyo9ob6tRek2a5az6rH5CVUW1UVnAQ50jSNMcYYU5ZlVVVyvK7rqqown8qAV1XV29sbjo/jiArLsizL0lqLD1AY5mJd0jk3jqMcRJ1t21ZVVRQFzu55nKJaATZIybZti6JADXIJ4ziWZYmS3kW5mGqlTim5ZFVo/+k8v2qnacJUq11b3YviQQ7DIJNy0zS6h7TipUBRFOha/CqGYZBikK98F+f1pCM/DA9PtcYYa638Cz+GoiimaWqaBq4LzutdlHYwwqlG/sRvb8UqOaIv8FyeX7UYQiAy8Qq0hyBdOI5jURTW2nBqjqo2nHOHYWjbtq5rjFjOub7v5bvzPMsA7DarFqIfhkGWa07JN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pdlaYwxxuiIbLi2ErgtJSWCu1Ev82xUbfQFGx2k58k06gzIuzcH4kVwR1tPzNaqlXhLR9VerT3FWOvUoALVSiypVm3UvERjrX4lbqnMIXgR3LvGWqr2xtqjLyFqz0w7u2FgsnYxoZLhgjfW6mWcdi7DoPKoarVfq1/ARFXRW2xhZPr2O8cyV1wlGsEtZ9RXGvq18qe3Gs6C01SrV8F64sbqHkt7Xd4LTMa7ABCTVNX3PY6M44gCUokEhntm6KByLKtxCl2/u6wXvUhn1Nn3vRcZ7ZybpklLYZcsdnnA3hVFWw8W4vLFfgTIt22Ldttu3iPAOIRUyDtFh7+QSKhakh9ULckPqpbkB1VL8oOqJfmRVrUfHx+3pjkhZJGPj4+EqiXkQaBqSX5QtSQ/qFqSH1QtyQ+qluQHVUvyg6ol+UHVkvygakl+ULUkP6hakh//B49cHz6aLmUaAAAAAElFTkSuQmCC" alt="" />
这里涉及到两个角色:
抽象模板(Abstract Template)角色有如下责任:
■ 定义了一个或多个抽象操作,以便让子类实现。这些抽象操作叫做基本操作,它们是一个顶级逻辑的组成步骤。
■ 定义并实现了一个模板方法。这个模板方法一般是一个具体方法,它给出了一个顶级逻辑的骨架,而逻辑的组成步骤在相应的抽象操作中,推迟到子类实现。顶级逻辑也有可能调用一些具体方法。
具体模板(Concrete Template)角色又如下责任:
■ 实现父类所定义的一个或多个抽象方法,它们是一个顶级逻辑的组成步骤。
■ 每一个抽象模板角色都可以有任意多个具体模板角色与之对应,而每一个具体模板角色都可以给出这些抽象方法(也就是顶级逻辑的组成步骤)的不同实现,从而使得顶级逻辑的实现各不相同。
源代码
抽象模板角色类,abstractMethod()、hookMethod()等基本方法是顶级逻辑的组成步骤,这个顶级逻辑由templateMethod()方法代表。
public abstract class AbstractTemplate {
/**
* 模板方法
*/
public void templateMethod(){
//调用基本方法
abstractMethod();
hookMethod();
concreteMethod();
}
/**
* 基本方法的声明(由子类实现)
*/
protected abstract void abstractMethod();
/**
* 基本方法(空方法)
*/
protected void hookMethod(){}
/**
* 基本方法(已经实现)
*/
private final void concreteMethod(){
//业务相关的代码
}
}
具体模板角色类,实现了父类所声明的基本方法,abstractMethod()方法所代表的就是强制子类实现的剩余逻辑,而hookMethod()方法是可选择实现的逻辑,不是必须实现的。
public class ConcreteTemplate extends AbstractTemplate{
//基本方法的实现
@Override
public void abstractMethod() {
//业务相关的代码
}
//重写父类的方法
@Override
public void hookMethod() {
//业务相关的代码
}
}
模板模式的关键是:子类可以置换掉父类的可变部分,但是子类却不可以改变模板方法所代表的顶级逻辑。
每当定义一个新的子类时,不要按照控制流程的思路去想,而应当按照“责任”的思路去想。换言之,应当考虑哪些操作是必须置换掉的,哪些操作是可以置换掉的,以及哪些操作是不可以置换掉的。使用模板模式可以使这些责任变得清晰。
模板方法模式中的方法
模板方法中的方法可以分为两大类:模板方法和基本方法。
模板方法
一个模板方法是定义在抽象类中的,把基本操作方法组合在一起形成一个总算法或一个总行为的方法。
一个抽象类可以有任意多个模板方法,而不限于一个。每一个模板方法都可以调用任意多个具体方法。
基本方法
基本方法又可以分为三种:抽象方法(Abstract Method)、具体方法(Concrete Method)和钩子方法(Hook Method)。
● 抽象方法:一个抽象方法由抽象类声明,由具体子类实现。在Java语言里抽象方法以abstract关键字标示。
● 具体方法:一个具体方法由抽象类声明并实现,而子类并不实现或置换。
● 钩子方法:一个钩子方法由抽象类声明并实现,而子类会加以扩展。通常抽象类给出的实现是一个空实现,作为方法的默认实现。
在上面的例子中,AbstractTemplate是一个抽象类,它带有三个方法。其中abstractMethod()是一个抽象方法,它由抽象类声明为抽象方法,并由子类实现;hookMethod()是一个钩子方法,它由抽象类声明并提供默认实现,并且由子类置换掉。concreteMethod()是一个具体方法,它由抽象类声明并实现。
默认钩子方法
一个钩子方法常常由抽象类给出一个空实现作为此方法的默认实现。这种空的钩子方法叫做“Do Nothing Hook”。显然,这种默认钩子方法在缺省适配模式里面已经见过了,一个缺省适配模式讲的是一个类为一个接口提供一个默认的空实现,从而使得缺省适配类的子类不必像实现接口那样必须给出所有方法的实现,因为通常一个具体类并不需要所有的方法。
命名规则
命名规则是设计师之间赖以沟通的管道之一,使用恰当的命名规则可以帮助不同设计师之间的沟通。
钩子方法的名字应当以do开始,这是熟悉设计模式的Java开发人员的标准做法。在上面的例子中,钩子方法hookMethod()应当以do开头;在HttpServlet类中,也遵从这一命名规则,如doGet()、doPost()等方法。
使用场景
考虑一个计算存款利息的例子。假设系统需要支持两种存款账号,即货币市场(Money Market)账号和定期存款(Certificate of Deposite)账号。这两种账号的存款利息是不同的,因此,在计算一个存户的存款利息额时,必须区分两种不同的账号类型。
这个系统的总行为应当是计算出利息,这也就决定了作为一个模板方法模式的顶级逻辑应当是利息计算。由于利息计算涉及到两个步骤:一个基本方法给出账号种类,另一个基本方法给出利息百分比。这两个基本方法构成具体逻辑,因为账号的类型不同,所以具体逻辑会有所不同。
显然,系统需要一个抽象角色给出顶级行为的实现,而将两个作为细节步骤的基本方法留给具体子类实现。由于需要考虑的账号有两种:一是货币市场账号,二是定期存款账号。系统的类结构如下图所示。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA3YAAAFECAIAAADk4jtVAAAgAElEQVR4nO29L6ztSHa37emZTCcDEil6ExKlUay0QuaGBVjpsAS2WcJaMhkyUoClHDYgsgIvsdRSBzQw6Msig6ihQUATS1GjltEN8sABBg39gfWdNetW2XW89/b29rGfB1zt42tXlevPqp+rVlVFIwAAAADAqkSPTgAAAAAAHA0kJgAAAACsDBITYHz//n0DALAP3r9//2ijCLACSEw4Oz/88EMEALAnvv3220ebRoBbQWLC2WmaJoqizz///DcAAI/miy++iKLo66+/frRpBLgVJCacHZGYGHQA2ANYJDgMSEw4Oxh0ANgPWCQ4DEhMODsYdADYD1gkOAxITDg7GHQA2A9YJDgMSEw4Oxh0ANgPWCQ4DEhMODsYdADYD1gkOAxITDg7GPTTUtd1HMd93z86IQC/B4sEhwGJCWcHg35asiyLoqiqqkcnxGUYhrIsH50KeAxYJDgMSEw4Oxj005IkSZIkW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V1RPj6PaMrQoyyQkp2YrNyU17SKXJaztDP7R0om2yvXbYqZJMnyFeWiYpum0RXlmpl5nmvp29wrikJqi/gSxHGsrhQ68OxrR7ve3MkTv7zgqCAx4TAgMeHsLDfofd9Pbmcomk9GrWT7HrkuElPxn5rcmkdvdrazsUE5q4XsjomTAfoX/XeZ/FO0joTg/3DS4GXY78N0diayurn19uyczC7FCllZ5DR3Z4ArzmH330Xw98XU6623gaiN3XlHyVWb7c4j4WyBw4DEhMOAxISzg0F/deR5Lt4Il26fDrB/sEhwGJCYcHYw6ACwH7BIcBiQmHB2MOgAsB+wSHAYkJhwdjDoALAfsEhwGJCYcHYw6ACwH7BIcBiQmHB2xKA/PT01AACP5u3bt0hMOAZITDg73333XQSwBj/5yU8enQQ4CN98882jTSPArSAxAcYvv/zyNwA38G//9m9/9Ed/FEXRT3/601/96lePTg68bt6+ffvjjz8+2i4C3AoSEwDgVj777LMoip6enn7+859/8sknj04OAMDjQWICANzEf//3f3/00Uf/9E//NI7j09OTaM1HJwoA4MEgMQEAbuJP//RPP/744/fv34/j+OOPP/7lX/7lz372s9/97nePThcAwCNBYgIAXE+WZVEUvX37Vq80TRNF0d/+7d8+MFUAAA8HiQkAcCXff//9z3/+81/+8pfO9S+++CKKonfv3j0kVQAAewCJCQBwJZ988kkURf/7v//rXP/tb6sqCO8AACAASURBVH/7Z3/2Z7/4xS+YLgeA04LEBAC4hn//93+Pouhf//VfJ//366+/jqLoH//xHzdOFQDATkBiAgBczO9+97uPP/74k08+Cexf+Pd///cfffTR//zP/2yZMACAnYDEBAC4mL/7u7+Loujbb78N3PP+/fuf//zn/+///b/NUgUAsB+QmAAAl/Hu3buf/vSn//zP//zinf/xH/8RRdGvf/3rDVIFALArkJgAAJfxi1/84k/+5E9++9vfvnjnjz/++Mtf/vJnP/vZ999/v0HCAAD2AxITAOACPv/88yiKvvzyy4X3f/fdd1EU/dVf/dVdUwUAsDeQmAAAS/n+++8/+uijf/iHf7joqV/96lfO9uwAAIcH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FiQlwDWJQmqa51EnxJNA8YQOoZvBA2raVkUv05RxITABYH5onbADVDGDPIDEBYH1onrABVDOAPYPEBID1oXnCBlDNAPYMEhMA1ofmCRtANQPYM69eYj49PTUAsDPevn1L3w/3pqEXANgxa3UED5CY3333XQQAO+abb77Z3jLAeaAXANg/t3cED5CY4zh++eWXvwGAXfL27dsff/zxIZYBzgO9AMCeWaUjeIzEBAAAAIADg8QEAAAAgJVBYgIAAADAyiAxAQAAAGBlkJgAAAAAsDJITAAAAABYGSQmAAAAAKzM/wdvw4yPvJRnjQAAAABJRU5ErkJggg==" alt="" />
源代码
抽象模板角色类
public abstract class Account {
/**
* 模板方法,计算利息数额
* @return 返回利息数额
*/
public final double calculateInterest(){
double interestRate = doCalculateInterestRate();
String accountType = doCalculateAccountType();
double amount = calculateAmount(accountType);
return amount * interestRate;
}
/**
* 基本方法留给子类实现
*/
protected abstract String doCalculateAccountType();
/**
* 基本方法留给子类实现
*/
protected abstract double doCalculateInterestRate();
/**
* 基本方法,已经实现
*/
private double calculateAmount(String accountType){
/**
* 省略相关的业务逻辑
*/
return 7243.00;
}
}
具体模板角色类
public class MoneyMarketAccount extends Account { @Override
protected String doCalculateAccountType() { return "Money Market";
} @Override
protected double doCalculateInterestRate() { return 0.045;
} }
public class CDAccount extends Account { @Override
protected String doCalculateAccountType() {
return "Certificate of Deposite";
} @Override
protected double doCalculateInterestRate() {
return 0.06;
} }
客户端类
public class Client { public static void main(String[] args) {
Account account = new MoneyMarketAccount();
System.out.println("货币市场账号的利息数额为:" + account.calculateInterest());
account = new CDAccount();
System.out.println("定期账号的利息数额为:" + account.calculateInterest());
} }
模板方法模式在Servlet中的应用
使用过Servlet的人都清楚,除了要在web.xml做相应的配置外,还需继承一个叫HttpServlet的抽象类。HttpService类提供了一个service()方法,这个方法调用七个do方法中的一个或几个,完成对客户端调用的响应。这些do方法需要由HttpServlet的具体子类提供,因此这是典型的模板方法模式。下面是service()方法的源代码:
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException { String method = req.getMethod(); if (method.equals(METHOD_GET)) {
long lastModified = getLastModified(req);
if (lastModified == -1) {
// servlet doesn't support if-modified-since, no reason
// to go through further expensive logic
doGet(req, resp);
} else {
long ifModifiedSince = req.getDateHeader(HEADER_IFMODSINCE);
if (ifModifiedSince < (lastModified / 1000 * 1000)) {
// If the servlet mod time is later, call doGet()
// Round down to the nearest second for a proper compare
// A ifModifiedSince of -1 will always be less
maybeSetLastModified(resp, lastModified);
doGet(req, resp);
} else {
resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
} } else if (method.equals(METHOD_HEAD)) {
long lastModified = getLastModified(req);
maybeSetLastModified(resp, lastModified);
doHead(req, resp); } else if (method.equals(METHOD_POST)) {
doPost(req, resp); } else if (method.equals(METHOD_PUT)) {
doPut(req, resp); } else if (method.equals(METHOD_DELETE)) {
doDelete(req, resp); } else if (method.equals(METHOD_OPTIONS)) {
doOptions(req,resp); } else if (method.equals(METHOD_TRACE)) {
doTrace(req,resp); } else {
//
// Note that this means NO servlet supports whatever
// method was requested, anywhere on this server.
// String errMsg = lStrings.getString("http.method_not_implemented");
Object[] errArgs = new Object[1];
errArgs[0] = method;
errMsg = MessageFormat.format(errMsg, errArgs); resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, errMsg);
}
}
当然,这个service()方法也可以被子类置换掉。
下面给出一个简单的Servlet例子:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUsAAAG6CAIAAAAOG/N1AAAgAElEQVR4nO2dL6/tuNnFL7rSy+6XiDTwwAsCBpaGFY4U0g8QUDYo6heIVDggoDioMLAkUuEoqCwDCwIu9AuWztPnPHZyvHf2PzvrB4728XYc7yTL/2Ivf3GEkHz58uwMEELuCBVOSM5Q4YTkDBVOSM48TuFvb29fCCFxvL293UR3j1P4ly9sLxASy630QoUT8opQ4YTkDBVOSM5Q4YTkDBVOSM5Q4WG6rnvAWR7DNE1d19V1fasE53m+YWr7TNM0TdO6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2+3Jb40iY9JciUfhT8eNLZvO8BGyG2hwgnJGSqckJyhwgnJGSqckJyhwm8MXq3hhdyz80JIXgr/1AFimqZpmjBB9R5vkvTr66ZpdtaxPwbaQpAkFX61A8QwDLLOrGma62wbIm0h1nWVcz0F2kIQl6jCr3aAMHXXddM5420hYmxkngUVfhLyUXiMA4RRuFmt4Vd3fuBFthBmLeoOtIUgdyIHhcc7QGgddl2nW+wYG9Ptahw+TVNVVdD5pbYQJsEdYmwh1nWtqgoFAX4y+gu0hSA7pKTw4w4Q0GfTNLoTrvvP4zhKESDiNAZP8bYQKB0O/GiLrKKZ51nyTFsIskNKCpfPV68PD7alt1ZoYvGm39CNt4W4x5A1zi6Nfy4aJ/tQ4ZsKB2g/6858vC2EXuN5K9BgofELiSRJhV/tABFUeLCVrofozFHxthDxKoq3hRjHEQMBwbPQFoIYklS4Id4Bous6GaDSQOS6E44uNEbajMFDpC3ERevG420hnPeSj7YQZIccFA4u8m+I5zpbiMj9la4jOOWGthAkSD4KfxHQ2D64KRoht4IKJyRnqHBCcoYKJyRnqHBCciYZhX/79u0LIeRCvn37dlB6rFoJyRkqnJCcocIJyRkqnJCcocIJyRkqnJCcocIJyRkqnJCcocIJyRkqnJCcocIJyRkqnJCcocIJyRkqnJCcocIJyZn/B5nGp/pAvJzjAAAAAElFTkSuQmCC" alt="" />
从上面的类图可以看出,TestServlet类是HttpServlet类的子类,并且置换掉了父类的两个方法:doGet()和doPost()。
public class TestServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { System.out.println("using the GET method"); } public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { System.out.println("using the POST method");
} }
从上面的例子可以看出这是一个典型的模板方法模式。
HttpServlet担任抽象模板角色
模板方法:由service()方法担任。
基本方法:由doPost()、doGet()等方法担任。
TestServlet担任具体模板角色
TestServlet置换掉了父类HttpServlet中七个基本方法中的其中两个,分别是doGet()和doPost()。
JAVA模板方法模式的更多相关文章
- 【Java】模板方法模式
今天介绍的是模板方法模式~ 模板方法模式,由父类定制总体的框架,具体的细节由子类实现. 一般来说,模板方法中有3类方法: 抽象方法,父类声明方法待子类具体实现.比如例子的validate.save.u ...
- JAVA 设计模式 模板方法模式
定义 模板方法模式 (Template Method) 定义了一个操作中的算法的骨架,而将部分步骤的实现在子类中完成. 模板方法模式使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 模 ...
- java模式之-模板方法模式
模板方法模式是java设计模式常见的模式之一. <JAVA与模式>中写道: 模板方法模式是类的行为模式.准备一个抽象类,将部分逻辑以具体方法以及具体构造函数的形式实现,然后声明一些抽象方法 ...
- (转)《JAVA与模式》之模板方法模式
该文章转自:http://www.cnblogs.com/java-my-life/archive/2012/05/14/2495235.html 在阎宏博士的<JAVA与模式>一书中开头 ...
- Java之模板方法模式(Template Method)
Java之模板方法模式(Template Method) 1. 概念:定义一个算法的骨架,而将一些实现步骤延迟到子类中. 把不变的行为搬到超类,去除子类中重复的代码来体现他的优势. 2. UML图: ...
- Java中类的继承,属性和方法的四种修饰符的作用范围,final关键字,java的三大特点中的2个:封装和多态,以及多态的一个设计模式,模板方法模式(template method)
(一)Java中的继承: 关于继承,在Java中类的继承只能是单继承,不像C+++那样灵活,可以多继承,多继承的后果就是各种关系乱套,就相当于一个孩子有2个母亲一样,社会关系的复杂,不利于程序后期的开 ...
- JAVA之旅(七)——final关键字 , 抽象类abstract,模板方法模式,接口interface,implements,特点,扩展
JAVA之旅(七)--final关键字 , 抽象类abstract,模板方法模式,接口interface,implements,特点,扩展 OK,我们继续学习JAVA,美滋滋的 一.final 我们来 ...
- 折腾Java设计模式之模板方法模式
博客原文地址:折腾Java设计模式之模板方法模式 模板方法模式 Define the skeleton of an algorithm in an operation, deferring some ...
- Java EE设计模式(主要简单介绍工厂模式,适配器模式和模板方法模式)
Java EE设计模式分为三种类型,共23种: 创建型模式:单例模式.抽象工厂模式.建造者模式.工厂模式.原型模式. 结构型模式:适配器模式.桥接模式.装饰模式.组合模式.外观模式.享元模式.代理模式 ...
随机推荐
- cf466B Wonder Room
B. Wonder Room time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- ALLEN-XIE
ALLEN-XIE ABOUT Allen Xie是一家坚持理念至上的西装定制店.我们的价值观渗透于我们所做的每一件事中,从而确保始终遵循自己的风格.我们坚持用最高标准要求自己,因此,在制衣过程中 ...
- Prime Ring Problem + nyoj 素数环 + Oil Deposits + Red and Black
Prime Ring Problem Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- SEO,你敢说你会吗?
SEO从何開始学起?SEO基础知识我们须要掌握哪些?SEO是什么?SEO究竟要怎么做?这些问题无时无刻不在困惑着我们.就我个人一些小观点来谈谈一个站点优化的大致步骤. SEO初期阶段 空间域名:空间跟 ...
- 数字温湿度传感器DHT11--操作源代码
//IO定义 #define P_DataIN_DHT11 PB0_IN #define P_DataOUT_DHT11 PB0_OUT //宏定义 #define BSET_DHT11 P_Data ...
- Web 开发中 9 个有用的提示和技巧
在本文中,我们给出 9 个有用的 HTML.CSS 和 JavaScript 的技巧和提示,可能在做 Web 开发中经常会需要用到的,其中有几个是关于 HTML5 和 CSS3 的,如果你是一个前端开 ...
- Invalid file permission Please regenerate them with cacaoadm create-keys --force
1.服务器重启之后,启动cacao报错,提示无效的文件权限. [root@ldapserver bin]# ./cacaoadm start Invalid file permission: [/ho ...
- asp.net MVC 验证注解
对于Web系统,对于用户的输入验证是必须的.不仅需要在客户端对用户的输入进行验证,在服务端也需要对用户的执行进行验证. asp.net MVC中对于验证提供了一种注解机制.注解是一种通用机制,可以用来 ...
- VMware linux 增加根目录空间 (使用图形分区工具gparted LiveCd)
写这篇文章的原因: 最近要给服务器Centos上的ruby版本升级,由于是第一次升级,不敢直接在服务器上操作. 所以在我的winxp上装了Vmware ,又在Vmware中装了Centos5.2. 用 ...
- Android 常用 adb 命令总结
Android 常用 adb 命令总结 针对移动端 Android 的测试, adb 命令是很重要的一个点,必须将常用的 adb 命令熟记于心, 将会为 Android 测试带来很大的方便,其中很多命 ...