设计模式
中国好胖子、
学不死就往死里学,比你优秀的人比你还努力,你还拿什么和别人拼
展开
-
观察者模式
观察者模式public class ObserverTest { public static void main(String[] args) { Subject subject = new Subject(); Task1 task1 = new Task1(); subject.addListener(task1); subject.addListener(new Task2()); subject.notifyObserver("xxx");原创 2020-06-18 17:44:38 · 132 阅读 · 0 评论 -
模板方法模式
模板方法模式public class TemplateMethodTest { public static void main(String[] args) { Abstract anAbstract = new ProcessSubClass(); anAbstract.operation(); }}abstract class Abstract { protected abstract void process(); public void operati原创 2020-06-18 17:43:25 · 103 阅读 · 0 评论 -
策略模式
策略模式package com.bigdata.strategy.v2;/** * Copyright (c) 2019 leyou ALL Rights Reserved Project: learning Package: com.bigdata.strategy.v2 * Version: 1.0 * * @author qingzhi.wu * @date 2020/6/18 14:01 */public class StrategyV2Test { public stati原创 2020-06-18 17:41:33 · 138 阅读 · 0 评论 -
装饰器模式
package com.bigdata.decorator;import java.util.Comparator;/** * Copyright (c) 2019 leyou ALL Rights Reserved * Project: learning * Package: com.bigdata.decorator * Version: 1.0 * * @author qingzhi.wu * @date 2020/6/18 13:39 */public class Deco原创 2020-06-18 17:40:23 · 123 阅读 · 0 评论 -
适配器模式
适配器模式package com.bigdata.adapter.v2;public class AdapterTest2 { public static void main(String[] args) { Adapter adapter = new Adapter(); adapter.output5v(); }}class Adaptee{ public int output220v(){ return 220; }}inte原创 2020-06-18 17:39:10 · 137 阅读 · 0 评论 -
外观模式
外观模式public class FacadeTest { public static void main(String[] args) { // }}class Client{ private Facade facade = new Facade(); public void dosmoething(){ facade.doSomething(); } }class Facade { private System原创 2020-06-16 22:13:44 · 131 阅读 · 0 评论 -
享元模式
享元模式public class FlyWeightTest { public static void main(String[] args) { TreeNode treeNode1 = new TreeNode(3,4, TreeFactory.getTree("xxx","xxx")); TreeNode treeNode2 = new TreeNode(2,22, TreeFactory.getTree("xxx","xxx")); Syst原创 2020-06-16 22:05:12 · 123 阅读 · 0 评论 -
建造者模式
建造者模式可以用在flink中,进行属性拉宽public class BuildorTost { public static void main(String[] args) { Product build = new Product.Builder() .setName("xxx") .setCompany("xxx") .build(); }}class Product { private Strin原创 2020-06-16 21:12:59 · 137 阅读 · 0 评论 -
工厂设计模式
简单工厂public class App { public static void main(String[] args) { Product a = SimpleFactory.createProduct("A"); a.method(); Product b = SimpleFactory.createProduct("B"); b.method(); }}interface Product { void method();}class Prod原创 2020-06-15 21:22:26 · 124 阅读 · 0 评论 -
单例设计模式
双端懒汉式单例设计模式public class LazySingleton { private static volatile LazySingleton instance; private LazySingleton() {} public static synchronized LazySingleton getInstance() { if (instance == null) { synchronized (LazySingleton.class) {原创 2020-06-15 20:22:49 · 88 阅读 · 0 评论