设计模式与UMl小结

最近看了java23种设计模式,鉴于自己的理解画了与之对应的UML图,有些理解的还不是很透彻,先做这一阶段的整理:(介绍和英文部分摘自维基百科)

 

创建型:
1.AbstractFactory(抽象工厂) 

提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类。

Provides one level of interface higher than the factory pattern. It is used to return one of several factories.



 
2.工厂方法模式(Factory Method Pattern)

定义一个用于创建对象的接口,让子类决定将哪一个类实例化。Factory Method使一个类的实例化延迟到其子类。

Provides an abstraction or an interface and lets subclass or implementing classes decide which class or method should be instantiated or called, based on the conditions or parameters given.



 


3.Builder(建造模式)

将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。

Construct a complex object from simple objects step by step.



 

4.Prototype(原始模型)

用原型实例指定创建对象的种类,并且通过拷贝这个原型来创建新的对象。


Cloning an object by reducing the cost of creation.



 
5.Singleton(单例模式)

保证一个类仅有一个实例,并提供一个访问它的全局访问点。

One instance of a class or one value accessible globally in an application.



 


结构型:
1.Adapter(适配器,变压器)

将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。

Convert the existing interfaces to a new interface to achieve compatibility and reusability of the unrelated classes in one application. Also known as Wrapper pattern.


 
2.Bridge(桥接模式)

将抽象部分与它的实现部分分离,使它们都可以独立地变化。

Decouple an abstraction or interface from its implementation so that the two can vary independently.


 
3.Composite(组合,合成)
介绍
将对象组合成树形结构以表示“部分-整体”的层次结构。它使得客户对单个对象和复合对象的使用具有一致性。
Build a complex object out of elemental objects and itself like a tree structure.


 
4.Decorator(装饰器)

动态地给一个对象添加一些额外的职责。就扩展功能而言,它比生成子类方式更为灵活。

Attach additional responsibilities or functions to an object dynamically or statically. Also known as Wrapper.


 
5、 外观模式或门面模式(Facade Pattern)

为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用

Make a complex system simpler by providing a unified or general interface, which is a higher layer to these subsystems.


 
6、 享元模式(Flyweight Pattern)

运用共享技术有效地支持大量细粒度的对象。

Make instances of classes on the fly to improve performance efficiently, like individual characters or icons on the screen.


 
7、代理模式(Proxy Pattern)

为其他对象提供一个代理以控制对这个对象的访问。

Use a simple object to represent a complex one or provide a placeholder for another object to control access to it.


 
行为型:

1、 责任链模式(Chain of Responsibility Pattern)

为解除请求的发送者和接收者之间耦合,而使多个对象都有机会处理这个请求。将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它。

Let more than one object handle a request without their knowing each other. Pass the request to chained objects until it has been handled.


 
2、命令模式(Command Pattern)

将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可取消的操作。

Streamlize objects by providing an interface to encapsulate a request and make the interface implemented by subclasses in order to parameterize the clients.


 
3、解释器模式(Interpreter Pattern)

给定一个语言,定义它的文法的一种表示,并定义一个解释器, 该解释器使用该表示来解释语言中的句子。

Provides a definition of a macro language or syntax and parsing into objects in a program.


 
4、 迭代器模式(Iterator Pattern)

提供一种方法顺序访问一个聚合对象中各个元素, 而又不需暴露该对象的内部表示。

Provide a way to move through a list of collection or aggregated objects without knowing its internal representations.


 
5、中介者模式(Mediator Pattern)

用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互。


 
Provide a way to move through a list of collection or aggregated objects without knowing its internal representations.

6、 备忘录模式(Memento Pattern)

在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。这样以后就可将该对象恢复到保存的状态。

To record an object internal state without violating encapsulation and reclaim it later without knowledge of the original object.


 
7、 观察者模式(Observer Pattern)

定义对象间的一种一对多的依赖关系,以便当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并自动刷新。

One object changes state, all of its dependents are updated automatically.


 
8、状态模式(State Pattern)

允许一个对象在其内部状态改变时改变它的行为。对象看起来似乎修改了它所属的类。

An object's behavior change is represented by its member classes, which share the same super class.


 
9、 策略模式(Strategy Pattern)

定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换。本模式使得算法的变化可独立于使用它的客户。

Group several algorithms in a single module to provide alternatives. Also known as policy.


 
10、模板方法模式(Template Method Pattern)

定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。Template Method使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。

Provide an abstract definition for a method or a class and redefine its behavior later or on the fly without changing its structure.


 

11、 访问者模式(Visitor Pattern)

表示一个作用于某对象结构中的各元素的操作。它使你可以在不改变各元素的类的前提下定义作用于这些元素的新操作。

Define a new operation to deal with the classes of the elements without changing their structures.