随笔分类 -  设计模式

摘要:软件架构设计原则: 开闭原则; 依赖倒置原则; 单一职责原则; 接口隔离原则; 迪米特法则; 里氏特换原则; 合用复用原则. 设计模式分类: 创建型设计模式: 简单工厂模式 工厂方法模式 抽象工厂模式 单例模式 原型模式 建造者模式 结构型设计模式: 代理模式 门面模式 装饰器模式 享元模式 组合模 阅读全文
posted @ 2021-05-02 16:51 justKen 阅读(26) 评论(0) 推荐(0) 编辑
摘要:委派模式 委派模式结构图: 示例代码: // 抽象任务类 public interface Task { void doTask(); } // 具体任务角色A public class ConcreteTaskA implements Task{ @Override public void doT 阅读全文
posted @ 2021-04-29 22:37 justKen 阅读(78) 评论(0) 推荐(0) 编辑
摘要:解释器模式 解释器模式结构图: 示例代码: // 抽象表达式角色 public interface ArithmeticInterpreter { int interpret(); } // 终结表达式角色 public abstract class Interpreter implements A 阅读全文
posted @ 2021-04-29 00:46 justKen 阅读(45) 评论(0) 推荐(0) 编辑
摘要:状态模式 状态模式结构图: 示例代码: // 抽象状态类 public abstract class Status { protected ApplicationContext context; public void setContext(ApplicationContext context) { 阅读全文
posted @ 2021-04-28 21:54 justKen 阅读(45) 评论(0) 推荐(0) 编辑
摘要:模板方法模式 模板方法模式结构图: 示例代码: // 测试类 public class TemplateMethodTest { public static void main(String[] args) { TemplateMethod method = new ConcreteMethod() 阅读全文
posted @ 2021-04-28 00:02 justKen 阅读(43) 评论(0) 推荐(0) 编辑
摘要:备忘录模式 备忘录模式原型图: 示例代码: // 抽象备忘录接口 public interface Memento { } // 发起人角色 @Data public class Originator { private String status; public Originator(String 阅读全文
posted @ 2021-04-27 08:14 justKen 阅读(45) 评论(0) 推荐(0) 编辑
摘要:原型模式 原型模式结构图: 示例代码: // 具体对象A,浅克隆 @Data public class ConcretePrototypeA implements Cloneable{ private String str; private List<String> list = new Array 阅读全文
posted @ 2021-04-26 23:23 justKen 阅读(26) 评论(0) 推荐(0) 编辑
摘要:命令模式 命令模式结构图: 示例代码: // 命令接受者,负责具体执行命令 public class Receiver { public void action(){ System.out.println("开始执行命令========"); } } // 命令抽象类 public interfac 阅读全文
posted @ 2021-04-25 07:37 justKen 阅读(40) 评论(0) 推荐(0) 编辑
摘要:桥接模式 桥接模式结构图: 示例代码: // 桥接角色Message接口 public interface Message { void sendMessage(String message, String toUser); } // 具体Message角色Email public class Em 阅读全文
posted @ 2021-04-24 23:54 justKen 阅读(64) 评论(0) 推荐(0) 编辑
摘要:适配器模式 适配器模式结构图: 示例代码: // 已有登录类实现 public class PassportService { public String regist(String userName, String password){ System.out.println("注册成功====== 阅读全文
posted @ 2021-04-24 20:40 justKen 阅读(48) 评论(0) 推荐(0) 编辑
摘要:建造者模式 建造者模式结构图: 示例代码: public class BuilderTest { public static void main(String[] args) { ConcreteBuilder builder = new ConcreteBuilder(); Product pro 阅读全文
posted @ 2021-04-22 23:52 justKen 阅读(43) 评论(0) 推荐(0) 编辑
摘要:访问者模式 访问者模式结构图: 示例代码: // 抽象访问者 public interface Visistor { void checkWork(Engineer engineer); void checkWork(Manager manager); } // 具体访问者boss public c 阅读全文
posted @ 2021-04-21 23:39 justKen 阅读(60) 评论(0) 推荐(0) 编辑
摘要:迭代器模式 迭代器模式结构图: 示例代码: // 抽象迭代器 public interface Iterator <E>{ boolean hasNext(); E next(); } // 具体迭代器 public class ConcreteIterator<E> implements Iter 阅读全文
posted @ 2021-04-19 07:34 justKen 阅读(51) 评论(0) 推荐(0) 编辑
摘要:代理模式 代理模式分为静态代理和动态代理.下图为静态代理结构图: 静态代理示例代码: // 抽象主题接口 public interface Subject { void request(); } // 具体主题角色 public class RealSubject implements Subjec 阅读全文
posted @ 2021-04-18 12:16 justKen 阅读(45) 评论(0) 推荐(0) 编辑
摘要:享元模式 享元模式结构图 示例代码 // 抽象享元角色 public interface Flyweight { void doSomething(); } // 具体享元角色 public class ConcreteFlyweight implements Flyweight{ private 阅读全文
posted @ 2021-04-17 17:07 justKen 阅读(41) 评论(0) 推荐(0) 编辑
摘要:组合模式 组合模式分为安全组合模式和透明组合模式,本文下的示例代码为透明组合模式,在叶子节点中冗余实现了叶子节点不需要的方法,而安全组合模式则需要进行叶子节点和普通节点的区分. 组合模式结构图 示例代码 // 抽象类 public abstract class Component { protect 阅读全文
posted @ 2021-04-17 13:47 justKen 阅读(58) 评论(0) 推荐(0) 编辑
摘要:观察者模式 观察者模式结构图 示例代码 // 抽象主题 public abstract class Subject { protected List<Observer> observers = new ArrayList<>(); protected Event event; public bool 阅读全文
posted @ 2021-04-17 11:46 justKen 阅读(38) 评论(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 阅读(33) 评论(0) 推荐(0) 编辑
摘要:责任链模式 责任链模式结构图 示例代码: // 抽象处理类 public abstract class Handler { protected Handler nextHandler; public void add(Handler handler){ this.nextHandler = hand 阅读全文
posted @ 2021-04-13 23:57 justKen 阅读(44) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示