设计模式
创建模式:
1. factory时的一系列初始化工作从构造方法中剥离出来;它们唯一的区别在于在创建类的复杂程度上,抽象工厂指的是将共同部分封装在抽象类中,将不同部分延伸到其子类中去。
2. singleton:确保系统中只有一个实例对象的存在。
3. builder
4. prototype:通过原型实例指定创建对象的类型,并且通过拷贝这些原型来创建新的对象。
结构模式:
1. flyweight:避免大量拥有相同内容的小类的开销。
2. bridge:将抽象和行为划分开来,使得它们各自独立,但又能够动态的结合。(继承抽象接口组合行为接口)。
3. decorator:动态的给一个对象添加一些额外的职责。
4. composite:将对象以树形结构的形式组合起来,已形成部分-到整体的层次结构,使客户端对单个对象和组合对象的使用具有一致性。
5. adapter:将原本两个没有关系的类结合在一起使用(有适配者和被适配者,您可以使用组合模式或者是继承模式)。
6. proxy:为其他对象提供一种代理以控制对这些对象的访问,典型的就是权限控制。
7. facade:为系统中的一组接口提供一个一致的界面。(典型的就是数据库jdbc的操作)。
行为模式:
1. Iterator:Iterator模式可以顺序的访问一个聚集中的元素而不必暴露该聚集的内部情况。
2. Template:定义操作中算法的骨架,将具体操作(一些步骤)的实现延迟到其子类中去。
3. chain of responsibility:通过一系列低耦合的类来试图处理一个request,唯一的共同点就是在它们之间传递request。
4. Memento:通过一个对象拷贝另外一个对象的内容状态,以将该对象恢复到原先保存的状态。
5. mediator:通过一个中介对象来封装一系列对象交互的行为,例如:Android中的Intent。
6. interpreter:定义语言的文法,并创建一个解释器来解释语言中的句子。
7. strategy:定义一系列的算法,并且把这些算法封装成单独的类。
8. state:不同的状态不同的行为。
9. Observer:当一个对象的内存状态发生变化时,Observer可以及时监听到这种变化。
10. Vistor:作用于某个对象群(Arrays或者是Collection)中各个对象的操作,它可以让你
在不改变这些对象本身的情况之下,定义作用于这些对象的新操作。
11. command:来自客户端的请求传入一个对象,我们无需知道该请求激活的动作以及接受
该请求的处理细节。
第二篇:23种设计模式(英语版)
Creational patterns
These patterns have to do with class instantiation. They can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation to get the job done.
Abstract Factory groups object factories that have a common theme.
Builder constructs complex objects by separating construction and representation. Factory Method creates objects without specifying the exact class to create.
Prototype creates objects by cloning an existing object.
Singleton restricts object creation for a class to only one instance.
Structural patterns
These concern class and object composition. They use inheritance to compose interfaces and define ways to compose objects to obtain new functionality.
Adapter allows classes with incompatible interfaces to work together by wrapping its own interface around that of an already existing class.
Bridge decouples an abstraction from its implementation so that the two can vary independently.
Composite composes zero-or-more similar objects so that they can be manipulated as one object.
Decorator dynamically adds/overrides behaviour in an existing method of an object. Facade provides a simplified interface to a large body of code.
Flyweight reduces the cost of creating and manipulating a large number of similar objects.
Proxy provides a placeholder for another object to control access, reduce cost, and reduce complexity.
Behavioral patterns
Most of these design patterns are specifically concerned with communication between objects.
Chain of responsibility delegates commands to a chain of processing objects. Command creates objects which encapsulate actions and parameters.
Interpreter implements a specialized language.
Iterator accesses the elements of an object sequentially without exposing its underlying representation.
Mediator allows loose coupling between classes by being the only class that has detailed knowledge of their methods.
Memento provides the ability to restore an object to its previous state (undo).
Observer is a publish/subscribe pattern which allows a number of observer objects to see an event.
State allows an object to alter its behavior when its internal state changes.
Strategy allows one of a family of algorithms to be selected on-the-fly at runtime.
Template method defines the skeleton of an algorithm as an abstract class, allowing its subclasses to provide concrete behavior.
Visitor separates an algorithm from an object structure by moving the hierarchy of methods into one object.
Circuit Breaker prevents using a broken external dependency (or internal component) until it comes back online