一、原则

1. 类设计原则

The Single-Responsibility Principle (SRP)

A class should have only one reason to change.

 

单一职责原则(SRP)

一个类应该仅有一个引起它变化的原因。

 

The Open/Closed Principle (OCP)

Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification.

 

开放封闭原则(OCP)

软件实体(类,模块,函数等等)应该是对扩展开放的,对修改封闭的。

 

The Liskov Substitution Principle (LSP)

Subtypes must be substitutable for their base types.

 

Liskov替换原则(LSP)

子类型必须能够替换掉它们的基类型。

 

The Interface Segregation Principle (ISP)

Clients should not be forced to depend on methods they do not use.

 

接口隔离原则(ISP)

不应该强迫客户依赖于它们不用的方法。

 

The Dependency-Inversion Principle (DIP)

A.High-level modules should not depend on low-level modules. Both should depend on abstractions.

B.Abstractions should not depend upon details. Details should depend upon abstractions.

 

依赖倒置原则(DIP)

A. 高层模块不应该依赖于低层模块。二者都应该依赖于抽象。

B. 抽象不应该依赖于细节。细节应该依赖于抽象。

 

The Least Knowledge Principle (LKP) (Law of Demeter)

Talk only to your immediate friends.

 

最少知识原则(LKP)(得墨忒耳定律)

只和你的密友谈话。

 

2. 组件内聚性原则

The Reuse/Release Equivalence Principle (REP)

The granule of reuse is the granule of release.

 

重用发布等价原则(REP)

重用的粒度就是发布的粒度。

 

The Common Reuse Principle (CRP)

The classes in a component are reused together. If you reuse one of the classes in a component, you reuse them all.

 

共同重用原则(CRP)

一个组件中的所有类应该是共同重用的。如果重用了组件中的一个类,那么就要重用组件中的所有类。

 

The Common Closure Principle (CCP)

The classes in a component should be closed together against the same kinds of changes. A change that affects a component affects all the classes in that component and no other components.

 

共同封闭原则(CCP)

组件中的所有类对于同一类性质的变化应该是共同封闭的。一个变化若对一个组件产生影响,则将对该组件中的所有类产生影响,而对于其它的组件不造成任何影响。

 

3. 组件耦合性原则

The Acyclic Dependencies Principle (ADP)

Allow no cycles in the component dependency graph.

 

无环依赖原则(ADP)

在组件的依赖关系图中不允许存在环。

 

The Stable-Dependencies Principle (SDP)

Depend in the direction of stability.

 

稳定依赖原则(SDP)

朝着稳定的方向进行依赖。

 

The Stable-Abstractions Principle (SAP)

A component should be as abstract as it is stable.

 

稳定抽象原则(SAP)

组件的抽象程度应该和其稳定程度一致。

 

二、模式

1. 创建模式

Abstract Factory

Provides an interface for creating families of related or dependent objects without specifying their concrete classes.

 

抽象工厂

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

 

Builder

Separate the construction of a complex object from its representation so that the same construction process can create different representations.

 

生成器

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

 

Factory Method

Defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

 

工厂方法

定义一个用于创建对象的接口,让子类决定实例化哪一个类。工厂方法让类把实例化推迟到子类。

 

Prototype

Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

 

原型

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

 

Singleton

Ensures a class has only one instance, and provides a global point of access to it.

 

单件

确保一个类只有一个实例,并提供一个全局访问点。

 

2. 结构模式

Adapter

Converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

 

适配器

将一个类的接口转换成客户希望的另外一个接口。适配器让原本接口不兼容而不能一起工作的那些类可以一起工作。

 

Bridge

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

 

桥接

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

 

Composite

Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

 

组合

将对象组合成树形结构以表示“整体/部分”的层次结构。组合能让客户以一致的方式处理个别对象和对象组合。

 

Decorator

Attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

 

装饰者

动态的给一个对象附加职责。为了扩展功能,装饰者提供了比继承更灵活的替代方案。

 

Facade

Provides a unified interface to a set of interfaces in a subsytem. Facade defines a higher-level interface that makes the subsystem easier to use.

 

外观

提供一个统一的接口,用于访问子系统中的一群接口。外观定义了一个高层接口,让子系统更容易使用。

 

Flyweight

Use sharing to support large numbers of fine-grained objects efficiently.

 

享元

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

 

Proxy

Provides a surrogate or placeholder for another object to control access to it.

 

代理

为另一个对象提供一个替身或占位符以控制对这个对象的访问。

 

3. 行为模式

Chain of Responsibility

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 object handles it.

 

职责链

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

 

Command

Encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations.

 

命令

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

 

Interpreter

Given a language, define a represention for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

 

解释器

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

 

Iterator

Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

 

迭代器

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

 

Mediator

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.

 

中介者

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

 

Memento

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

 

备忘录

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

 

Observer

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

 

观察者

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

 

State

Allows an object to alter its behavior when its internal state changes. The object will appear to change its class.

 

状态

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

 

Strategy

Defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

 

策略

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

 

Template Method

Defines the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.

 

模板方法

在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中。模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤。

 

Visitor

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.

 

访问者

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

posted on 2011-07-10 15:46  ideasea  阅读(315)  评论(0)    收藏  举报