设计模式
文章平均质量分 60
梅啉豆
写点自己的总结也不错~
展开
-
10-责任链模式
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原创 2018-01-21 08:23:06 · 264 阅读 · 0 评论 -
25——对象池模式(新)
对象池模式,或者称为对象池服务,其意图如下: 通过循环使用对象,减少资源在初始化和释放时的昂贵损耗1.类图2.代码/*** 对象池示例代码*/public abstract class ObjectPool { //容器,容纳对象 private Hashtable pool = new Hashtable(); //初始化时创原创 2018-01-26 10:59:13 · 436 阅读 · 0 评论 -
26——雇工模式(新)
雇工模式也叫做仆人模式(Servant Design Pattern),其意图是: 雇工模式是行为模式的一种,它为一组类提供通用的功能,而不需要类实现这些功能,它是命令模式的一种扩展。1.类图2.代码/*** 通用功能*/public interface IServiced { //具有的特质或功能 public void ser原创 2018-01-26 11:03:12 · 555 阅读 · 1 评论 -
27——黑板模式(新)
1.意图 黑板模式(Blackboard Design Pattern)是观察者模式的一个扩展,知名度并不高,但是我们使用的范围却非常广。黑板模式的意图如下: 允许消息的读写同时进行,广泛地交互消息看到这个图大家可能会说:这不是一个简单的消息广播吗?是的,确实如此,黑板模式确实是消息的广播,主要解决的问题是消息的生产者和消费者之间的耦合问题,它的核心是消息存储(黑板),它存原创 2018-01-26 11:07:03 · 1148 阅读 · 0 评论 -
9-命令模式
1.定义 命令模式是一个高内聚的模式,其定义为:Encapsulate a request as an object,thereby letting you parameterize clients with different requests,queue or log requests,and support undoable operations.(将一个请求封装成一个对象,从而让你原创 2018-01-20 13:40:33 · 287 阅读 · 0 评论 -
1-单例模式
1.定义: Ensure a class has only one instance, and provide a global point of access to it.(确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例。)——个人理解 意思就是运行过程中只创建一个实例。2.类图:3.代码: 一提单例模式都知道两个模式原创 2018-01-20 10:18:15 · 236 阅读 · 0 评论 -
2-工厂方法模式
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.(定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法使原创 2018-01-20 10:56:47 · 223 阅读 · 0 评论 -
3-抽象工厂模式
1.定义 Provide an interface for creating families of related or dependent objects without specifying their concrete classes.(为创建一组相关或相互依赖的对象提供一个接口,而且无须指定它们 的具体类。)2.类图3.代码/***原创 2018-01-20 11:34:51 · 199 阅读 · 0 评论 -
4-模板方法模式
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原创 2018-01-20 11:56:27 · 213 阅读 · 0 评论 -
5-建造者模式
1.定义建造者模式(Builder Pattern)也叫做生成器模式,其定义如下: Separate the construction of a complex object from its representation so that the same construction process can create different representations.(将一个复杂对原创 2018-01-20 12:06:23 · 242 阅读 · 0 评论 -
6-代理模式
1.定义 Provide a surrogate or placeholder for another object to control access to it.(为其他对象提供一种代理以控制对这个对象的访问。)2.类图3.代码/*** 抽象主题类*/public interface Subject { //定义一个方法 p原创 2018-01-20 12:54:25 · 242 阅读 · 0 评论 -
7-原型模式
1.定义 Specify the kinds of objects to create using a prototypical instance,and create new objects by copying this prototype.(用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。)2.类图3.代码/*** 原型模式通用原创 2018-01-20 13:19:37 · 248 阅读 · 0 评论 -
24——规格模式(新)
它是组合模式的一种特殊应用1.类图2.代码/*** 抽象规格书*/public interface ISpecification { //候选者是否满足要求 public boolean isSatisfiedBy(Object candidate); //and操作 public ISpecification and(原创 2018-01-26 10:54:06 · 513 阅读 · 0 评论 -
23——桥梁模式
1.定义 桥梁模式(Bridge Pattern)也叫做桥接模式,是一个比较简单的模式,其定义如下:Decouple an abstraction from its implementation so that the two can vary independently.(将抽象和实现解耦,使得两者可以独立地变化。)2.类图Abstraction——抽象化角色原创 2018-01-26 10:41:14 · 259 阅读 · 0 评论 -
11-装饰模式
1.定义 装饰模式(Decorator Pattern)是一种比较常见的模式,其定义如下:Attach additional responsibilities to an object dynamically keeping the same interface.Decorators provide a flexible alternative to subclassing for ext原创 2018-01-21 08:23:23 · 205 阅读 · 0 评论 -
12-策略模式
1.定义 策略模式(Strategy Pattern)是一种比较简单的模式,也叫做政策模式(Policy Pattern)。其定义如下: Define a family of algorithms,encapsulate each one,and make them interchangeable.(定义一组算法,将每个算法都封装起来,并且使它们之间可以互换。)2.类图原创 2018-01-21 08:23:37 · 252 阅读 · 0 评论 -
13-适配器模式
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.(将一个类的接口变换成客户端所期待的另一种接口,从而原创 2018-01-21 08:23:48 · 259 阅读 · 0 评论 -
14-迭代器模式
1.定义 迭代器模式(Iterator Pattern)目前已经是一个没落的模式,基本上没人会单独写一个迭代器,除非是产品性质的开发,其定义如下: Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation原创 2018-01-21 08:24:02 · 216 阅读 · 0 评论 -
15-组合模式
1.定义 Compose objects into tree structures to represent part-whole hierarchies.Composite lets clients treat individual objects and compositions of objects uniformly.(将对象组合成树形结构以表示“部分-整体”的层次结构,使得用户对原创 2018-01-21 08:24:15 · 224 阅读 · 0 评论 -
16-观察者模式
1.定义 观察者模式(Observer Pattern)也叫做发布订阅模式(Publish/subscribe),它是一个在项目中经常使用的模式,其定义如下: > Define a one-to-many dependency between objects so that when one object changes state,all its dependents ar原创 2018-01-21 08:24:26 · 227 阅读 · 0 评论 -
17-门面模式
1.定义 门面模式(Facade Pattern)也叫做外观模式,是一种比较常用的封装模式,其定义如下: Provide a unified interface to a set of interfaces in a subsystem.Facade defines a higher-level interface that makes the subsystem easier to原创 2018-01-22 08:02:41 · 199 阅读 · 0 评论 -
18-备忘录模式
1.定义备忘录模式(Memento Pattern)提供了一种弥补真实世界缺陷的方法,让“后悔药”在程序的世界中真实可行,其定义如下: Without violating encapsulation,capture and externalize an object’s internal state so that the object can be restored to this原创 2018-01-22 09:23:52 · 217 阅读 · 0 评论 -
19-访问者模式
1.定义 访问者模式(Visitor Pattern)是一个相对简单的模式,其定义如下:Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classe原创 2018-01-23 09:11:05 · 364 阅读 · 0 评论 -
20——状态模式
1.定义 Allow an object to alter its behavior when its internal state changes.The object will appear to change its class.(当一个对象内在状态改变时允许其改变行为,这个对象看起来像改变了其类。)2.类图State——抽象状态角色接口或抽象类,负责对原创 2018-01-25 19:44:50 · 280 阅读 · 0 评论 -
21——解释器模式
1.定义 解释器模式(Interpreter Pattern)是一种按照规定语法进行解析的方案,在现在项目中使用较少,其定义如下:Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sente原创 2018-01-26 09:28:35 · 303 阅读 · 0 评论 -
22——享元模式
1.定义 享元模式(Flyweight Pattern)是池技术的重要实现方式,其定义如下:Use sharing to support large numbers of fine-grained objects efficiently.(使用共享对象可有效地支持大量的细粒度的对象。)内部状态内部状态是对象可共享出来的信息,存储在享元对象内部并且不会随环境改变而改变。外原创 2018-01-26 10:15:17 · 320 阅读 · 0 评论 -
8-中介者模式
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 interac原创 2018-01-20 13:29:24 · 254 阅读 · 0 评论