01
将一个请求封装为一个对象,从而使用户可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可撤销的操作。
何时使用:
优点:
一个对象有多种操作,但是我们不希望调用者(请求者)直接使用,我们就额外添加一个对象,然后让调用者通过这个对象来使用那些操作。比如,我们有一个类可以在磁盘上新建或是删除文件(接收者),但是我们不希望直接提供给别人(请求者)使用,所以我们就为它的各种操作创建对应的命令
//接收者
public class MakeFile {
//新建文件
public void createFile(String name) throws IOException{
File file = new File(name);
file.createNewFile();
}
//删除文件
public boolean deleteFile(String name){
File file = new File(name);
if(file.exists()&&file.isFile()){
file.delete();
return true;
}
return false;
}
}
//命令接口
public interface Command {
void execute(String name) throws Exception;
}
//新建文件命令
public class CommandCreate implements Command {
MakeFile makeFile;
public CommandCreate(MakeFile makeFile) {
this.makeFile = makeFile;
}
@Override
public void execute(String name) throws Exception {
makeFile.createFile(name);
}
}
//删文件命令
public class CommandDelete implements Command{
MakeFile makeFile;
public CommandDelete(MakeFile makeFile) {
this.makeFile = makeFile;
}
@Override
public void execute(String name) throws Exception {
makeFile.deleteFile(name);
}
}
//请求者
public class Client {
Command command;
public Client setCommand(Command command){
this.command = command;
return this;
}
public void executeCommand(String name) throws Exception{
if(command==null)
throw new Exception("命令不能为空!");
command.execute(name);
}
}
public class Test {
public static void main(String args[]) throws Exception{
//接收者
MakeFile makeFile = new MakeFile();
//命令
CommandCreate create = new CommandCreate(makeFile);
CommandDelete delete = new CommandDelete(makeFile);
//请求者
Client client = new Client();
//执行命令
client.setCommand(create).executeCommand("d://test1.txt");
client.setCommand(create).executeCommand("d://test2.txt");
client.setCommand(delete).executeCommand("d://test2.txt");
}
}//执行完后在D盘会有一个test1.txt的文件,test2.txt本页创建了,不过又被删除了
命令模式不宜滥用,比如:使用这种模式,会多出来很多对象(命令)。
02
简述TCP和UDP的区别
tcp 和 udp 是 OSI 模型中的运输层中的协议。tcp 提供可靠的通信传输,而 udp 则常被用于让广播和细节控制交给应用的通信传输。
两者的区别大致如下:
03
Android网络数据的加密方式
对称加密,就是加密和解密数据都是使用同一个key,这方面的算法有DES。
非对称加密,加密和解密是使用不同的key。发送数据之前要先和服务端约定生成公钥和私钥,使用公钥加密的数据可以用私钥解密,反之。这方面的算法有RSA。ssh 和 ssl都是典型的非对称加密。
04
Http和Https的区别
HTTP:超文本传输协议(HyperText Transfer Protocol),是目前互联网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标准。设计HTTP最初的目的是为了提供一种发布和接收HTML页面的方法。现在主要是一个客户端和服务器端请求和应答的标准(TCP),但是正在被HTTPS取代。
HTTPS:安全套接字层超文本传输协议(Hyper Text Transfer Protocol over Secure Socket Layer)或超文本传输安全协议(Hypertext Transfer Protocol Secure),由网景公司(Netscape)于1994年创建的,是以安全为目标的HTTP通道。简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。
主要区别:
附:https优缺点:
优点:
缺点:
进阶Http:https://mp.weixin.qq.com/s/3TaonTzAsqqLLbJ-yrwNdw
进阶Https:https://mp.weixin.qq.com/s/lCr7NuQNLQh4Ake8yXorxg?scene=25#wechat_redirect
05
简述apk打包流程
注:工具位置基于win平台. 参考连接:
https://developer.android.com/studio/build/index.html?hl=zh-cn#build-processhttps://blog.csdn.net/jiangwei0910410003/article/details/50402000