
设计模式
大音希声_
大音希声。大象无形。
展开
-
设计模式之责任链模式(附:spring mvc中HandlerExecutionChain源码应用分析)
一、概述1、定义 Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.Chain the receiving objects and pass the request along the chain until an object原创 2020-07-28 12:03:31 · 702 阅读 · 2 评论 -
设计模式之策略模式(附:Arrays源码中策略模式使用分析)
一、概述1、定义 Define a family of algorithms,encapsulate each one,and make them interchangeable.(定义一组算法,将每个算法都封装起来,并且使它们之间可以互换。)2、通用类图3、基本介绍策略模式中,定义算法族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化独立于使用算法的客户;策略模式中体现了几个设计原则:①原创 2020-07-27 16:51:17 · 361 阅读 · 0 评论 -
设计模式之状态模式
一、概述1、定义 Allow an object to alter its behavior when its internal state changes.The object will appear to change its class.(当一个对象内在状态改变时允许其改变行为,这个对象看起来像改变了其类。)2、通用类图3、基本介绍主要用来解决对象在多种状态转换时,需要对外输出不同的行为的问题。原创 2020-07-27 11:27:36 · 142 阅读 · 0 评论 -
设计模式之解释器模式(附:SpelExpressionParser中解释器模式应用分析)
一、定义1、定义 Given a language,define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.(给定一门语言,定义它的语法的一种表示,并定义一个解释器,该解释器使用该解释来解释语言中的句子原创 2020-07-26 20:47:49 · 3161 阅读 · 0 评论 -
设计模式之备忘录模式
一、概述1、定义 Without violating encapsulation,capture and externalize an objects internal state so that the object can be restored to this state later.(在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。这样以后就可将该对象恢复到原先保存的状态。)原创 2020-07-26 16:29:19 · 109 阅读 · 0 评论 -
设计模式之中介者模式
一、概述1、定义 Define an object that encapsulates how a set of objects interact.Mediator promotes loose coupling by keeping objects from referring to each other explicitly,and it lets you vary their interaction in原创 2020-07-26 13:03:31 · 145 阅读 · 0 评论 -
设计模式之观察者模式(附:Observable源码应用分析)
一、概述1、定义 Define a one-to-many dependency between objects so that when one object changes state,all its dependents are notified and updated automatically.(定义对象间一种一对多的依赖关系,使得每当一个对象改变状态,则所有依赖于它的对象都会得到通知并被自动更新。)原创 2020-07-26 10:31:05 · 248 阅读 · 0 评论 -
设计模式之迭代器模式(附:ArrayList源码应用分析)
一、概述1、定义 Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.(它提供一种方法访问一个容器对象中各个元素,而又不需暴露该对象的内部细节。)2、通用类图3、基本介绍迭代器模式属于行为型模式,提供一种遍历集合元素原创 2020-07-25 16:39:16 · 239 阅读 · 0 评论 -
设计模式之访问者模式
一、概述1、定义 Represent an operation to be performed on the elements of an object structure.Visitor lets you define a new operation without changing the classes of the elements on which it operates.(封装一些作用于某种数据结构原创 2020-07-25 11:01:00 · 152 阅读 · 0 评论 -
设计模式之命令模式(附:JdbcTemplate中命令模式的应用分析)
一、概述1、定义 Encapsulate a request as an object,thereby letting you parameterize clients with different requests,queue or log requests,and support undoable operations.(将一个请求封装成一个对象,从而让你使用不同的请求把客户端参数化,对请求排队或者记录请求原创 2020-07-24 22:44:07 · 314 阅读 · 0 评论 -
设计模式之模板方法模式(附:IOC源码中模板方法模式的使用)
一、概述1、定义 Define the skeleton of an algorithm in an operation,deferring some steps to subclasses.Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structu原创 2020-07-24 10:44:32 · 330 阅读 · 0 评论 -
设计模式之代理模式(静态代理、动态代理与Cglib代理)
一、概述1、定义 Provide a surrogate or placeholder for another object to control access to it.(为其他对象提供一种代理以控制对整个对象的访问。)2、通用类图3、基本介绍代理模式:为对象提供一个替身,以控制这个对象的访问。即通过代理对象访问目标对象,这样还可以在目标对象实现的基础上,扩展目标对象的功能;被代理的对象可以是远原创 2020-07-23 17:20:04 · 174 阅读 · 0 评论 -
设计模式之享元模式(附:JDK-Integer的应用源码分析)
一、概述1、定义 Use sharing to support large numbers of fine-grained objects efficiently.(使用共享对象可有效地支持大量的细粒度的对象。)2、通用类图3、基本介绍享元模式可以通过运用共享技术有效的支持大量细粒度的对象;享元模式常用于系统底层的开发,解决系统的性能问题,例如数据库连接池,里面都是创建好的对象,我们使用的时候如果池原创 2020-07-20 20:53:02 · 269 阅读 · 0 评论 -
设计模式之外观模式(附:MyBatis中Configuration的外观模式的使用分析)
一、概述1、定义 Provide a unified interface to a set of interfaces in a subsystem.Facade defines a higher-level interface that makes the subsystem easier to use.(要求一个系统的外部与其内部的通信必须通过一个统一的对象进行。外观模式提供一个高层次的接口,使得子系统更容原创 2020-07-20 11:04:33 · 425 阅读 · 0 评论 -
设计模式之组合模式(HashMap源码中组合模式的使用)
一、概述1、定义 Compose objects into tree structures to represent part-whole hierarches.Composite lets clients treat individual objects and compositions of objects uniformly.(将对象组合成树形结构以表示“部分-整体”的层次结构使得用户对单个对象和组合对象原创 2020-06-15 21:43:41 · 1125 阅读 · 1 评论 -
设计模式之装饰模式(IO源码结构分析)
一、概述1、定义 Attach additional responsibilities to an object dynamically keeping the same interface.Decorators provide a flexible alternative to subclassing for extending functionality.(动态的给一个对象添加一些额外的职责。就增加功能来说原创 2020-06-15 17:02:39 · 257 阅读 · 0 评论 -
设计模式之桥接模式(JDBC源码结构分析)
一、概述1、定义 Decouple an abstraction from its implementation so that the two can vary independently.(将抽象和实现解耦,使得两者可以独立的变化)2、通用类图3、基本介绍 桥梁模式基于类的最小设计原则,通过使用封装、聚合及原创 2020-06-15 09:58:56 · 403 阅读 · 0 评论 -
设计模式之适配器模式(类适配器与对象适配器)
一、概述1、定义 Convert the interface of a class into another interface clients expect.Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.(将一个类的接口变成客户端所期待的另一种接口,从而使原本因接口不匹原创 2020-06-14 20:44:52 · 2282 阅读 · 1 评论 -
设计模式之建造者模式(附StringBuilder源码分析)
一、概述1、定义 Separate the construction of a complex object from its representation so that the same construction process can create different representations.(将一个复杂对象的构建与他的表示分离,使得同样的构建过程可以创建不同的表示。)2、通用类图3、建造者原创 2020-06-14 11:44:16 · 705 阅读 · 0 评论 -
设计模式之原型模式(浅拷贝与深拷贝详解,以及通过对象序列化实现深拷贝)
一、概述1、定义 Specify the kinds of objects to create using a prototypical instance,and create new objects by copying this prototype.(用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象)2、通用类图3、基本介绍原型模式是指:用原型实例指定创建对象的种类,并且通过拷贝这些原创 2020-06-13 22:56:53 · 473 阅读 · 0 评论 -
设计模式之抽象工厂模式
一、概述1、定义 Provide an interface for creating families of related or dependent objects without specifying their concrete classes.(为创建一组相关或相互依赖的对象提供一个接口,而且无需指定他们的具体类。)2、通用类图3、基本介绍抽象工厂模式定义了一个interface用于创建相关或原创 2020-06-13 15:15:14 · 177 阅读 · 0 评论 -
设计模式之工厂方法模式(附:Calendar源码分析)
一、概述1、定义 Define an interface for creating an object,but let subclasses decide which class to instantiate.Factory Method lets a class defer instantiation to subclasses.(定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法使一个类的实例化原创 2020-06-13 13:08:23 · 623 阅读 · 0 评论 -
设计模式之单例模式详解(饿汉式、懒汉式以及jdk源码使用举例)
一、概述1、定义 Ensure a class has only one instance,and provide a global point of access to it。(确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例)。2、单例模式的通用类图:3、单例模式的几种实现饿汉式(静态常量)饿汉式(静态代码块)懒汉式(线程不安全)懒汉式(线程安全,同步方法)双重检查静态内原创 2020-06-12 22:05:45 · 706 阅读 · 0 评论 -
类图六大关系总结
一、类图定义 用于描述系统中类(对象)本身的组成和类(对象)之间的各种静态关系。二、类之间的关系 六大关系:依赖、泛化(继承)、实现、关联、聚合与组合。 讲类之间的关系之前,先说一下类图中属性和方法前面的-,+,#的代表的原创 2020-06-12 17:46:41 · 16081 阅读 · 3 评论 -
设计模式之迪米特法则
一、定义 迪米特法则(Law of Demeter,LoD)也称为最少知识原则(Least Knowledge Principle,LKP),其定义是:一个对象应该对其它对象有最少的了解。 通俗的讲就是一个类应该对自己需要耦合或调用的类知道的最少,被耦合或调用的类的内部是如何复杂都与我没有关系。二、只和直接朋友交流原创 2020-06-12 13:08:16 · 192 阅读 · 0 评论