Adapter:to provide the interface that a client expects while using the services of a class with a different interface.
接口的转换, 将一个类的接口转换成客户希望的另外一个接口。Java中的WindowAdapter,就是这个,熟悉吧。
Facade:to provide an interface that makes a subsystem easy to use.
为子系统中的一组接口提供一个一致的界面, 定义了一个高层接口, 这个接口使得这一子系统更加容易使用。我的感觉就是,对外屏蔽所有的底层细节。用户只需要了解这个facade接口就可以了,其他的我全部不关心。
Composite: to let clients treat individual obects and compositions of objects uniformly.
将对象组合成树形结构表示'整体-部分'的层次结构
Bridge:to decouple an abstraction from the implementation of its abstract operations, so that the abstraction and its implementation can vary independently.
将抽象部分与它的实现部分分离,使它们都可以独立地变化。这个不是很好理解。。。汗。。贴两篇其他文章:http://www.jdon.com/designpatterns/bridge.htm,http://smartfool.javaeye.com/blog/74659
Singleton: to ensure that a class has only instance and to provide a global point of access to it.
保证一个类仅有一个实例, 并提供一个访问它的全局访问点。就是一个类只能实例化一个对象。有恶汉,懒汉模式之分。
Observer: to define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified so that they can react to the change.
定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时, 所有依赖于它的对象都得到通知并被自动更新。这个模式相当的有用,就有点像那个消息通讯机制,有消息来了就通知你,没消息就啥都不管。Java中的Observer已经实现了这个模式。
Mediator: to define an object that encapsulates how a set of objects interact; this promotes loose coupling, keeping the objects from referring to one another explicitly, and lets you vary their interaction independently.
用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显式
Proxy: to control access to an object by providing a surrogate, or placeholder, for it.
为其他对象提供一种代理以控制对这个对象的访问。想一下网关,很相似。
Chain of responsibility: to avoid coupling the sender of a request to its receiver, by giving more than one object a change to handle the request.
使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的
Flyweight: to use sharing to support large numbers of fine-grained objects efficiently.
运用共享技术有效地支持大量细粒度的对象。目的是,通过共享来达到减少内存消耗的目的,与cache不同,cache是利用局部性原理(时间局部性或者空间局部性)来提高查询命中率。
Builder: to move the construction logic for an object outside the class to be instantiated.
将一个复杂对象的构建与其表示相分离,使得同样的构建过程可以创建
Factory Method: to let a class developer define the interface for creating an object while retaining control of which class to instantiate.
定义一个用于创建对象的接口,而让子类来决定实例化哪一个类
AbstractFactory: to allow the creation of families of related or dependent objects.
提供一个创建一系列相关或相互依赖对象的接口,而无须指定它们具体
Prototype: to provide new objects by copying an example rather than by bringing forth new, uninitialized instance of a class.
用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象
Memento: to provide storage and restoration of an object's state.
在不破坏封装性的前提下,捕获一个对象的内部状态
Template method: to implement an algorithm in a method, deferring the definition of some steps of the algorithm so that other classes can redefine them.
使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。 Java抽象类,本身就是一个模板方法。模板方法的关键是:继承。与strategy其实有点类似。
State: to distribute state-specific logic across classes that represent an object's state.
允许一个对象在其内部状态改变时改变它的行为。貌似实现TCP这个比较有用,下次仔细研究下。
Strategy: to encapsulate alternative approaches, or strategies, in separate classes that each implement a common operation.
Strategy模式允许多种策略共存,而代码不会混乱
Command: to encapsulate a request in an object.将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数
Interpreter: to let you compose executable objects according to a set of composition rules that you define.
给定一个语言,定义它的文法的一种表示,并定义一种解释器
Decorator: to let you compose new variationsof an operation at runtime.
动态地给一个对象添加一些额外的职责。Java的IO流,很多都用了这个模式。如 PrintStream pbs = new PrintStream( new BufferedOutputStream( new FileOutputStream( "test.bat" ) ) );(也许写错了单词)
Iterator: to provide a way to access the elements of a collection sequentially.
提供一种方法顺序访问一个聚合对象中各个元素, 而又不需暴露该对象的内部表示。就是为了实现对象遍历。C++与JAVA的遍历器都属此类吧。
Visitor: to let you define a new operation for a hierarchy without changing the hierarchy classes.
表示一个作用于某对象结构中的各元素的操作。这个还晕乎中。
以上英文摘自《JAVA设计模式手册》
我对设计模式的理解是:
达到 对修改封闭,扩展开放 的目的
面向接口编程,或者面向抽象编程
优先使用对象组合,而不是类继承
寻找可能的变化并对象并进行抽象