设计模式
1: 责任链模式 ------》事件分发机制中 ViewGroup 和View 对事件的分发和消费。 okHttp中对请求的拦截器
代码:
2: 单例模式 -----》饿汉式和懒汉式
/**
* 单例设计模式
*/
public class SingleInstancePattern {
private static volatile SingleInstancePattern instance;
// 懒汉式(直接定义成静态变量,跟随类的加载而生成这个单例)
private static SingleInstancePattern instancePattern = new SingleInstancePattern();
private SingleInstancePattern() {
}
// 饿汉式
public static SingleInstancePattern getInstance() {
if (instance == null) {
synchronized (SingleInstancePattern.class) {
if (instance == null) {
instance = new SingleInstancePattern();
}
}
}
return instance;
}
public static SingleInstancePattern getInstancePattern() {
return instancePattern;
}
}
3: 工厂模式