![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
设计模式
Jack_Young_
这个作者很懒,什么都没留下…
展开
-
设计模式-工厂方法
public class FactoryMethod { public static void main(String[] args) { Product product = SimpleFactory.createProduct(); } } class SimpleFactory { public static Product createProduct() { return new ProductA(); } } interfac.原创 2021-06-26 15:59:36 · 49 阅读 · 0 评论 -
设计模式-抽象工厂
public class AbstractFactory { public static void main(String[] args) { IDatabaseUtils iDatabaseUtils = new MysqlDatabaseUtils(); IConnect connection = iDatabaseUtils.getConnection(); connection.connect(); ICommand comm.原创 2021-06-26 16:11:29 · 74 阅读 · 0 评论 -
设计模式-单例模式
1.懒汉模式 public class LazySingleton { private static LazySingleton instance; private LazySingleton() { } public static LazySingleton getInstance() { if (instance == null) { synchronized (LazySingleton.class) {原创 2021-06-26 15:08:44 · 58 阅读 · 0 评论 -
设计模式-建造者模式
建造者模式原创 2021-06-26 16:13:37 · 49 阅读 · 0 评论 -
设计模式-原型模式
原型模式 public class Prototype { public static void main(String[] args) throws CloneNotSupportedException { Product product = new Product(); product.setName("abc"); System.out.println(product); Product clone = product.clo原创 2021-06-28 20:06:17 · 90 阅读 · 0 评论 -
设计模式-责任链模式
责任链模式 public class ChainOfResponsibility { public static void main(String[] args) { Request request = new Request(false, true, true, true); RequestFreHandler requestFreHandler = new RequestFreHandler(new LoginHandler(null)); i原创 2021-06-28 20:05:13 · 64 阅读 · 0 评论 -
设计模式-观察者模式
观察者模式 public class ObserverMode { public static void main(String[] args) { Subject subject = new Subject(); Task1 task1 = new Task1(); subject.add(task1); subject.add(new Task2()); subject.notifyObserver("xx");原创 2021-06-28 20:05:22 · 68 阅读 · 0 评论 -
设计模式-模板方法
模板方法:执行的特定步骤到子类 public class TemplateMode { public static void main(String[] args) { AbstractClass subClass = new SubClass(); subClass.operation(); subClass.template(); } } abstract class AbstractClass { public void o原创 2021-06-28 20:05:31 · 54 阅读 · 0 评论 -
设计模式-策略模式
策略模式 public class StrategyTest { public static void main(String[] args) { Normal normal = new Normal(); normal.diaplay(); normal.attack(); normal.move(); } } interface Moveable { void move(); } interface Atta原创 2021-06-28 20:05:39 · 86 阅读 · 0 评论 -
设计模式-装饰者模式
装饰者模式,应用场景,扩展功能 public class DecorateMode { public static void main(String[] args) { Component c = new ConDec222(new ConDec(new ConcreteComponent())); c.operation(); } } interface Component { void operation(); } class Concre原创 2021-06-28 20:05:47 · 47 阅读 · 0 评论 -
设计模式-适配器模式
适配器模式主要解决兼容问题 对象适配器模式,类的适配器模式 对象适配器模式 public class AdapterMode1 { public static void main(String[] args) { Adapters adapters = new Adapters(new Adapter()); System.out.println(adapters.output5()); } } class Adapter { public原创 2021-06-28 20:05:54 · 75 阅读 · 0 评论 -
设计模式-门面模式
门面模式:为一组接口提供一个一致的接口,门面模式定义了一个高层接口,使得子系统便于使用。 public class Facade { public static void main(String[] args) { Client client = new Client(); client.doSomething(); } } class Client { Util util = new Util(); public void doSom原创 2021-06-28 20:06:02 · 71 阅读 · 0 评论 -
设计模式-享元模式
享元模式,指数据共享 public class FlyWeight { public static void main(String[] args) { TreeNode treeNode = new TreeNode(3, 4, TreeFactory.getTree("a")); System.out.println(treeNode); } } class TreeNode { private int x; private int原创 2021-06-28 20:06:10 · 109 阅读 · 0 评论