GOF23种设计模式类型、描述和类图(中)

GOF23种设计模式类型、描述和类图(中)

责任链模式

类型:行为

描述: 使多个对象都有机会处理请求,从而避免了请求的发送者和接受者之间的耦合关系,将这些对象连成一条链,并沿着这条链传递该请求,直到有对象处理为止。

责任链模式英文原话是:

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 object and pass the request along the chain until an object handles it.

类图

GOF23种设计模式类型、描述和类图(中)

观察者模式

类型:行为

描述:  定义对象间一种一对多的依赖关系,使得每当一个对象改变状态,所有依赖于它的对象都会得到通知并被自动更新。

英文原话:

Define a one-to-many dependency between objects so that when one object changes state,all its dependents are notified and updated automatically.

类图

GOF23种设计模式类型、描述和类图(中)

中介者模式

类型:行为

描述: 用一个中介者对象封装一系列对象(同事)的交互,中介者使各对象不需要显示的相互作用,从而使其耦合松散,而且中介者可以独立地改变它们之间的交互。

英文描述:

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 independently.

类图

GOF23种设计模式类型、描述和类图(中)

备忘录模式

类型:行为

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

英文描述:

Without violating encapsulation,capture and externalize an object's internal state so that the object can be restored to this state later.

类图

GOF23种设计模式类型、描述和类图(中)

状态模式

类型:行为

描述:  允许一个对象内在状态发生改变时改变行为,使得这个对象看起来像改变了类型。状态模式的核心是封装,状态的变更引起行为的变动,从外部看来就好像该对象对应的类发生改变一样。

英文描述:

Allow an object to alert its behavior when its internal state changes.The object will appear to change its class.

类图

GOF23种设计模式类型、描述和类图(中)

策略模式

类型:行为

描述:  定义一组算法,将每个算法都封装起来,并且是他们之间可以相互切换。类似于“条条大路通罗马”。

英文描述:

Define a family of algorithms,encapsulate each one,and make them interchangeable.

类图

GOF23种设计模式类型、描述和类图(中)

模板方法模式

类型:行为

描述:  定义一个操作汇总的算法的骨架,然后将一些步骤延迟到子类中。是得子类可以不改变一个算法的结构即可以重新定义该算法的某些特定步骤。

英文描述:

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 structure.

类图

GOF23种设计模式类型、描述和类图(中)

访问者模式

类型:行为

描述:  封装一些作用于某些数据结构中的个元素的操作,它可以在不改变数据结构的前提下定义作用这些元素的新的操作。

英文描述:

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.

类图

GOF23种设计模式类型、描述和类图(中)

来都来了 点个赞再走吧~~~

GOF23种设计模式类型、描述和类图(中)