设计模式实战案例
文章平均质量分 85
数据知道
IT技术博主,博主会持续更新专栏文章,欢迎关注和订阅文章博客,欢迎私信和博主交流技术。如有需要请站内私信或者联系VX名片(ID:data_know)
展开
-
单例模式详解(附常见的7种单例模式源码)
单例模式(Singleton Pattern):保证一个类仅有一个对象,并提供一个访问它的全局访问点。(Ensure a class only has one instance,and provide a globe point of access to it.)常见应用场景:Windows的Task Manager(任务管理器)就是很典型的单例模式windows的Recycle Bin(......原创 2019-05-24 16:22:18 · 15092 阅读 · 5 评论 -
原型模式详解 (附java语言源码)
原型模式(Prototype Pattern):用原型实例指定创建对象的种类,并且通过拷贝这个原型来创建新的对象。(Specify the kinds of objects to create using a prototypical instance, and create new objects by copying the prototype.)通过原型模式,绕过构造方法创建对象,利...原创 2019-06-04 17:49:38 · 16631 阅读 · 0 评论 -
桥接模式详解 (附java语言源码)
桥接模式(Bridge Pattern) :将抽象部分与它的实现部分分离,使他们都可以独立地变化。(Decouple an abstraction from its implementation so that the two can vary independently.)就像一个桥,将两个变化维度连接起来。各个维度都可以独立的变化。故称之为:桥接模式核心要点 : 处理多层继承结构,处...原创 2019-06-11 09:08:50 · 18497 阅读 · 0 评论 -
备忘录模式详解 (附java语言源码)
备忘录模式(Memento Pattern):在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保持该状态,这样以后就可以将该对象恢复到保存的状态。(Without violating encapsulates, capture and externalize an object’s internal state so that the object can be restored...原创 2019-06-20 19:52:04 · 28206 阅读 · 0 评论 -
组合模式详解 (附java语言源码)
组合模式(Composite Pattern):将对象组合成树形结构以表示“部分-整体”的层次结构。Composite 使得客户对单个对象和复合对象的使用具有一致性。(Compose object into tree structures torepresent part-whole hierarchy. Composite lets clients treat individual obje...原创 2019-06-11 15:09:08 · 18351 阅读 · 1 评论 -
命令模式详解 (附java语言源码)
命令模式(Command Pattern):将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化,对请求排队或记录请求日志,以及支持可取消的操作。(Encapsulate a request as an object,thereby letting you parameterize clients with different requests, queue or log requ...原创 2019-06-17 18:22:41 · 23543 阅读 · 1 评论 -
迭代器模式详解 (附java语言源码)
迭代器模式(Iterator Pattern):提供一种方法顺序访问一个聚合对象中各个元素,而又不需暴露该对象的内部表示。(Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.)开发中常见的场景:JD...原创 2019-06-18 19:19:43 · 23347 阅读 · 0 评论 -
解释器模式详解 (没有附java语言源码)
解释器模式(Interpreter Pattern):定义一个语言,定义它的文法的一种表示,并定义一个解释器,该解释器使用该表示来解释语言中的句子。(Given a language, define are presentation for its grammar along with an interpreter that uses there presentation to interpr...原创 2019-06-24 09:05:51 · 27318 阅读 · 0 评论 -
状态模式详解 (附java语言源码)
状态模式(State Pattern):允许一个对象在其内部状态改变时改变它的行为。对象看起来似乎修改了它所属的类。(Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.)核心:用于解决系统中 复杂对象的状态转换 以...原创 2019-06-24 09:32:01 · 27989 阅读 · 0 评论 -
访问者模式详解 (没有附java语言源码)
访问者模式(Visitor Pattern):表示一个作用于某对象结构中的各元素的操作。它使你可以在不改变各元素类别的前提下定义作用于这些元素的新操作。(Represent an operation to be performedon the elements of an object structure. Visitor lets you define a new operation wit...原创 2019-06-24 09:41:46 · 27411 阅读 · 0 评论 -
责任链模式详解 (附java语言源码)
责任链模式(Chain of Responsibility Pattern):为解除请求的发送者和接收者之间的耦合,而使多个对象都有机会处理这个请求。将这些对象连成一条链,并沿着这条链传递该请求,直到有对象处理它。(Avoid coupling the sender of a requestits receiver by giving more than one object a chance...原创 2019-06-24 10:27:25 · 28763 阅读 · 1 评论 -
中介者模式详解 (附java语言源码)
中介者模式(Mediator Pattern):用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显示地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。(Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping ...原创 2019-06-19 18:01:31 · 27671 阅读 · 0 评论 -
代理模式详解 (附java语言源码)
代理模式(Proxy Pattern):为其他对象提供一个代理以控制对这个对象的访问。(Provide a surrogate or placeholder foranther object to control access to it.)可以详细控制访问某个(某类)对象的方法,在调用这个方法前做前置处理,调用这个方法后做后置处理。分类:静态代理(静态定义代理类)动态代理(动态生...原创 2019-06-03 14:23:36 · 15270 阅读 · 0 评论 -
模板方法模式详解 (附java语言源码)
模版方法模式(Template Pattern):定义一个操作中的算法的骨架,而将一些步骤延迟到子类。TemplateMethod 使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。(Define the skeleton of an algorithm inan operation, deferring some steps to subclasses. Template Me...原创 2019-06-14 14:27:43 · 21584 阅读 · 0 评论 -
策略模式详解(用java语言实现策略模式)
策略模式(Strategy Pattern):定义一系列的算法,把它们一个个封装起来,并且使他们可相互替换。本模式使得算法的变化可以独立于使用它的客户。(Define a family of algorithms,encapsulate each one and make them interchangeable.Strategy lets the algorithmvary independ......原创 2019-05-27 13:00:40 · 25084 阅读 · 12 评论 -
装饰模式详解 (附java语言源码)
装饰模式(Decorator Pattern):动态地给一个对象添加一些额外的职责。就扩展功能而言,Decorator模式比生成子类的方式更为灵活。(Attach additional responsibilities to an object dynamically. Decorators provides a flexible alternative to subclasses for e...原创 2019-05-30 11:32:24 · 8643 阅读 · 0 评论 -
设计模式概述 以及 23种设计模式的介绍
设计模式概述(Design pattern):设计模式:代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段时间的试验和错误总结出来的。设计模式是一套被反复使用的、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了重用代码、让代码更容易被他人理解、保证代码可......原创 2019-05-24 11:05:39 · 96474 阅读 · 2 评论 -
观察者模式详解 (附java语言源码)
观察者模式(Observer Pattern):定义对象间的一种一对多的依赖关系,以便当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并自动刷新。(Define a one-to-many dependency between objects so that when one object changes state all its dependents are notified an...原创 2019-05-28 18:17:01 · 8357 阅读 · 0 评论 -
适配器模式详解 (附java语言源码)
适配器模式(Adapter Pattern):将一个类的接口转换成客户希望的另一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。(Convert the interface of a class into another interface clients except. Adapter lets classes work together that cou...原创 2019-06-05 18:19:04 · 17736 阅读 · 0 评论 -
工厂模式详解 (附java语言源码)
工厂模式(Factory Pattern):定义一个用于创建对象的接口,让子类决定将哪一个类实例化,FactoryMethod使一个类的实例化延迟到其子类。(Define an interface for creating anobject, but let subclasses decide which class to instantiate. Factory methodlets a c...原创 2019-05-31 16:05:49 · 14162 阅读 · 0 评论 -
抽象工厂模式详解 (附java语言源码)
抽象工厂模式(Abstract Factory Pattern):提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们的具体类。(Provide an interface for creating families of related or dependent object without specifying their concrete classes.)抽象工厂模式是工厂方法...原创 2019-05-31 20:02:30 · 14319 阅读 · 0 评论 -
建造者模式详解 (附java语言源码)
建造者模式(Builder Pattern):将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。(Separate the construction of a complex object from its representation so that the same construction process can create different represen...原创 2019-05-29 11:03:01 · 11700 阅读 · 3 评论 -
外观模式详解 (附java语言源码)
外观模式(Facade Pattern):为子系统中的一组接口提供一个一致的接口。Façade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。(Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes th...原创 2019-06-13 09:44:28 · 19242 阅读 · 0 评论 -
享元模式详解 (附java语言源码)
享元模式(Flyweight Pattern):运用共享技术有效地支持大量细粒度的对象。(Use sharing to support large numbers offine-grained objects efficiently.)享元模式核心:享元模式以共享的方式高效地支持大量细粒度对象的重用。享元对象能做到共享的关键是区分了内部状态和外部状态。• 内部状态:可以共享,不会随...原创 2019-06-13 19:11:09 · 21942 阅读 · 2 评论 -
设计模式之6大设计原则详解
1、单一职责原则There should never be more than one reason for a class to change.理解:不同的类具备不同的职责,各司其职。做系统设计是,如果发现有一个类拥有了两种职责,那么就要问一个问题:可以将这个类分成两个类吗?如果真的有必要,那就分开,千万不要让一个类干的事情太多。总结:一个类只承担一个职责2、开放封闭原则Soft...原创 2019-06-29 22:56:16 · 31287 阅读 · 1 评论