摘要: 访问者模式 访问者模式结构图: 示例代码: // 抽象访问者 public interface Visistor { void checkWork(Engineer engineer); void checkWork(Manager manager); } // 具体访问者boss public c 阅读全文
posted @ 2021-04-21 23:39 justKen 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 迭代器模式 迭代器模式结构图: 示例代码: // 抽象迭代器 public interface Iterator <E>{ boolean hasNext(); E next(); } // 具体迭代器 public class ConcreteIterator<E> implements Iter 阅读全文
posted @ 2021-04-19 07:34 justKen 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 代理模式 代理模式分为静态代理和动态代理.下图为静态代理结构图: 静态代理示例代码: // 抽象主题接口 public interface Subject { void request(); } // 具体主题角色 public class RealSubject implements Subjec 阅读全文
posted @ 2021-04-18 12:16 justKen 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 享元模式 享元模式结构图 示例代码 // 抽象享元角色 public interface Flyweight { void doSomething(); } // 具体享元角色 public class ConcreteFlyweight implements Flyweight{ private 阅读全文
posted @ 2021-04-17 17:07 justKen 阅读(38) 评论(0) 推荐(0) 编辑
摘要: 组合模式 组合模式分为安全组合模式和透明组合模式,本文下的示例代码为透明组合模式,在叶子节点中冗余实现了叶子节点不需要的方法,而安全组合模式则需要进行叶子节点和普通节点的区分. 组合模式结构图 示例代码 // 抽象类 public abstract class Component { protect 阅读全文
posted @ 2021-04-17 13:47 justKen 阅读(54) 评论(0) 推荐(0) 编辑
摘要: 观察者模式 观察者模式结构图 示例代码 // 抽象主题 public abstract class Subject { protected List<Observer> observers = new ArrayList<>(); protected Event event; public bool 阅读全文
posted @ 2021-04-17 11:46 justKen 阅读(37) 评论(0) 推荐(0) 编辑
摘要: ### 中介者模式,又称为调停者模式或调解者模式 1.中介者模式结构图 示例代码 // 抽象中介类 public abstract class Mediator { protected ConcreteColleagueA concreteColleagueA; protected Concrete 阅读全文
posted @ 2021-04-16 23:26 justKen 阅读(57) 评论(0) 推荐(0) 编辑
摘要: 装饰器模式 装饰器模式结构图 示例代码: // 抽象公共类 public abstract class Component { public abstract void work(); } // 具体被装饰对象 public class People extends Component{ @Over 阅读全文
posted @ 2021-04-16 07:46 justKen 阅读(30) 评论(0) 推荐(0) 编辑
摘要: 责任链模式 责任链模式结构图 示例代码: // 抽象处理类 public abstract class Handler { protected Handler nextHandler; public void add(Handler handler){ this.nextHandler = hand 阅读全文
posted @ 2021-04-13 23:57 justKen 阅读(41) 评论(0) 推荐(0) 编辑
摘要: 门面模式(外观模式) 门面模式结构图 示例代码: public class FacadeTest { public static void main(String[] args) { Facade facade = new Facade(); facade.doWork(); } // 子系统A s 阅读全文
posted @ 2021-04-12 23:41 justKen 阅读(37) 评论(0) 推荐(0) 编辑