
设计模式
文章平均质量分 82
秀强
物有本末,事有终始。
展开
-
Visitor访问者模式
文章目录Visitor patternStructureExampleSummaryVisitor patternIn object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object struc...原创 2020-03-01 12:35:51 · 321 阅读 · 0 评论 -
State状态设计模式
文章目录State patternStructureExampleSummaryState patternThe state pattern is a behavioral software design pattern that allows an object to alter its behavior when its internal state changes. This patt...原创 2020-02-29 18:23:26 · 150 阅读 · 0 评论 -
TemplateMethod模板方法
文章目录Template method patternStructureExampleSummaryTemplate method patternIn object-oriented programming, the template method is one of the behavioral design patterns identified by Gamma et al.[1] i...原创 2020-09-09 19:13:21 · 278 阅读 · 0 评论 -
Memento备忘录模式
文章目录Memento patternStructureExampleSummaryMemento patternThe memento pattern is a software design pattern that provides the ability to restore an object to its previous state (undo via rollback).T...原创 2020-02-28 21:24:47 · 195 阅读 · 0 评论 -
Prototype原型模式
文章目录Prototype patternStructureExample浅克隆深克隆String需要进一步深克隆么SummaryPrototype patternThe prototype pattern is a creational design pattern in software development. It is used when the type of objects t...原创 2020-02-28 20:41:49 · 201 阅读 · 0 评论 -
Command命令模式
文章目录别名Command patternStructure别名Action/TranscationCommand patternIn object-oriented programming, the command pattern is a behavioral design pattern in which an object is used to encapsulate all i...原创 2020-02-28 16:53:24 · 238 阅读 · 0 评论 -
Bridge桥接模式
文章目录Bridge patternStructureExampleSummaryBridge patternThe bridge pattern is a design pattern used in software engineering that is meant to “decouple an abstraction from its implementation so that ...原创 2020-02-28 16:19:01 · 237 阅读 · 0 评论 -
Adapter适配器模式
Adapter patternIn software engineering, the adapter pattern is a software design pattern (also known as wrapper, an alternative naming shared with the decorator pattern) that allows the interface of...原创 2020-02-28 00:24:06 · 147 阅读 · 0 评论 -
Builder构建器模式
文章目录Builder patternStructureExample1Example2SummaryBuilder patternThe builder pattern is a design pattern designed to provide a flexible solution to various object creation problems in object-orien...原创 2020-02-27 21:17:15 · 231 阅读 · 0 评论 -
Iterator迭代器模式
文章目录Iterator patternStructureExampleJDKSummaryIterator patternIn object-oriented programming, the iterator pattern is a design pattern in which an iterator is used to traverse a container and acces...原创 2020-09-09 19:13:31 · 259 阅读 · 0 评论 -
Proxy代理模式(三)cglib动态代理
文章目录加入cglib依赖cglib生成代理总结加入cglib依赖 <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>3.2.12&...原创 2020-02-25 23:54:24 · 199 阅读 · 0 评论 -
Proxy代理模式(二)JDK动态代理
文章目录jdk动态代理ExampleProxy.newProxyInstanceJDK动态代理的缺点jdk动态代理Exampleimport java.lang.reflect.InvocationHandler;import java.lang.reflect.Method;import java.lang.reflect.Proxy;import java.util.Random;...原创 2020-02-25 22:38:39 · 412 阅读 · 0 评论 -
Proxy代理模式(一)静态代理
文章目录Proxy patternStructureExampleSummaryProxy patternIn computer programming, the proxy pattern is a software design pattern. A proxy, in its most general form, is a class functioning as an interfa...原创 2020-02-25 01:17:22 · 256 阅读 · 0 评论 -
Flyweight享元模式
文章目录定义结构例子String intern()总结定义In computer programming, flyweight is a software design pattern. A flyweight is an object that minimizes memory usage by sharing as much data as possible with other sim...原创 2020-02-24 22:42:34 · 181 阅读 · 0 评论 -
Composite组合模式
文章目录定义结构Demo总结定义In software engineering, the composite pattern is a partitioning design pattern. The composite pattern describes a group of objects that are treated the same way as a single instanc...原创 2020-02-24 22:21:31 · 300 阅读 · 0 评论 -
Observer观察者模式
定义观察者模式是软件设计模式的一种。在此种模式中,一个目标对象管理所有相依于它的观察者对象,并且在它本身的状态改变时主动发出通知。这通常透过呼叫各观察者所提供的方法来实现。此种模式通常被用来实时事件处理系统。—维基百科结构Demoimport java.util.ArrayList;import java.util.List;public class Test { publ...原创 2020-02-24 21:54:31 · 255 阅读 · 0 评论 -
ChainOfResponsibility责任链设计模式
定义责任链模式在面向对象程式设计里是一种软件设计模式,它包含了一些命令对象和一系列的处理对象。每一个处理对 象决定它能处理哪些命令对象,它也知道如何将它不能处理的命令对象传递给该链中的下一个处理对象。该模式还描述了往该处理链的末尾添加新的处理对象的方法。 —维基百科模拟 Servlet FilterChain实现功能:现在有 2 个 Filter HTMLFilter 和 Sensiti...原创 2020-09-09 19:13:44 · 317 阅读 · 0 评论 -
Decorator装饰器模式
文章目录定义例子代码定义装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其结构。例子在不修改DataServiceImpl的情况下给DataServiceImpl增加日志功能和缓存功能。代码DataService.java package com.github.hcsp; public interface DataServ...原创 2020-09-09 19:16:31 · 196 阅读 · 0 评论 -
Factory工厂设计模式
文章目录定义不使用工厂模式使用工厂模式静态工厂动态工厂(通过反射)使用泛型改造动态工厂定义任何可以产生对象的方法或类,都可以称之为工厂单例也是一种工厂为什么有了new之后,还要有工厂?灵活控制生产过程权限、修饰、日志…不使用工厂模式package com.company;interface IFood{ //定义一个食物标准 public void eat(); ...原创 2020-02-23 22:25:41 · 244 阅读 · 0 评论 -
Singleton单例设计模式
文章目录特点饿汉式 常用懒汉式线程不安全双重检查 判断静态内部类方式 - 完美枚举单例 出自 effective java在Java哪里使用到了单例设计模式?懒汉式单例设计模式问题?特点构造方法私有化,类内部提供static方法获取实例化对象。这样不管外部如何操作永远都只有一个实例化对象。饿汉式 常用 package com.company; /** * ...原创 2020-09-09 19:16:09 · 234 阅读 · 0 评论 -
Strategy pattern
策略模式高内聚了不变的流程,将变化的流程抽象为策略接口。即封装不变,暴露变化。原创 2020-09-09 19:17:09 · 339 阅读 · 1 评论