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

单例模式

类型:创造

描述:Java 中最简单的设计模式之一。这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式。这种模式涉及到一个单一的类,该类负责创建自己的对象,同时确保只有单个对象被创建。这个类提供了一种访问其唯一的对象的方式,可以直接访问,不需要实例化该类的对象。

英文描述:

Ensure a class has only one instance,and provide a global point of access to it.

类图

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

工厂方法模式

类型:创造

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

英文描述:

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

类图

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

抽象工厂模式

类型:创造

描述:  为创建一组相关或者相互依赖的对象提供一个接口,而且无需指定他们的具体类。

英文描述:

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

类图

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

建造者模式

类型:创造

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

英文描述:

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

类图

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

原型模式

类型:创造

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

英文描述:

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

类图

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

迭代器模式

类型:创造

描述:  提供一种方法访问一个容器对象中各个元素,而不暴露该对象的内部细节。

英文描述:

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

类图

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

命令模式

类型:行为

描述:  一种数据驱动的设计模式,它属于行为型模式。请求以命令的形式包裹在对象中,并传给调用对象。调用对象寻找可以处理该命令的合适的对象,并把该命令传给相应的对象,该对象执行命令。

英文描述:

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

类图

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

解释器模式

类型:行为

描述:  提供了评估语言的语法或表达式的方式,它属于行为型模式。这种模式实现了一个表达式接口,该接口解释一个特定的上下文。这种模式被用在 SQL 解析、符号处理引擎等。

英文描述:

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

类图

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