Design Patterns Overview
2016-05-30 14:11
519 查看
Design Patterns Overview
目录
Design Patterns Overview目录
什么是GoF
用途
划分依据
具体分类1
Summary
什么是GoF?
提到设计模式,就不得不提到GoF。1994年,Erich Gamma, Richard Helm, Ralph Johnson 和 John Vlissides
出版了一本名叫Design Patterns - Elements of Reusable Object-Oriented Software 的书,而这恐怕也是设计模式这个词的起源了。
四位牛哄哄的大侠从此有了响当当的名号——GoF(Gang of Four,四人帮!)
根据四位大神的大作,设计模式基本上基于以下OOD的原则:
面向接口编程而不是面向实现编程
优先使用组合而不是继承
用途
在软件开发中,设计模式主要用于以下两方面:开发者之间的交流
设计模式提供了一些通用的术语,并且每种模式都适用于特定的场景。这样开发者交流起来就方便多了。比如一个人说我的代码用了单例模式,那么其他人不用追究细节就知道他是怎么实现的了(我觉得这个是最重要的)。
最佳实践
设计模式已经被证明在软件开发过程中能够为一些问题提供最好的解决方案。并且学习设计模式会让经验不足的开发者简单快速的了解软件设计。
划分依据
参考Design Patterns - Elements of Reusable Object-Oriented Software,设计模式可以分为23种,共3大类。Creational, Structural and Behavioral patterns。
当然还有其他的分类。
J2EE design patterns
Creational Patterns
划分依据:创建对象
这类模式关注的是对象的创建,并且在创建对象的同时隐藏创建的逻辑,而不是直接使用new操作符。这样对象的创建就更加灵活了,可以根据给定的场景来创建合适的对象。
Structural Patterns
划分依据:类和对象的组合
这类模式关注的是类和对象的组合。通过不同的组合带来更多功能上的变化。
Behavioral Patterns
划分依据:对象之间的交互
这类模式关注的是对象与对象之间的交互(communication)。
J2EE Patterns
划分依据:用于Java EE
具体分类1
CreationalPatterns | Description |
---|---|
Abstract Factory | Sets of methods to make various objects. |
Builder | Make and return one object various ways. |
Factory | Methods to make and return components of one object various ways. |
Prototype | Make new objects by cloning the objects which you set as prototypes. |
Singleton | A class distributes the only instance of itself. |
StructuralPatterns | Description |
---|---|
Adapter | A class extends another class, takes in an object, and makes the taken object behave like the extended class. |
Bridge | An abstraction and implementation are in different class hierarchies. |
Composite | Assemble groups of objects with the same signature. |
Decorator | One class takes in another class, both of which extend the same abstract class, and adds functionality. |
Facade | One class has a method that performs a complex process calling several other classes. |
Flyweight | The reusable and variable parts of a class are broken into two classes to save resources. |
Proxy | One class controls the creation of and access to objects in another class. |
BehavioralPatterns | Description |
---|---|
Chain of Resp. | A method called in one class can move up a hierarchy to find an object that can properly execute the method. |
Command | An object encapsulates everything needed to execute a method in another object. |
Interpreter | Define a macro language and syntax, parsing input into objects which perform the correct opertaions. |
Iterator | One object can traverse the elements of another object. |
Mediator | An object distributes communication between two or more objects. |
Memento | One object stores another objects state. |
Observer | An object notifies other object(s) if it changes. |
State | An object appears to change its` class when the class it passes calls through to switches itself for a related class. |
Strategy | An object controls which of a family of methods is called. Each method is in its` own class that extends a common base class. |
Template | An abstract class defines various methods, and has one non-overridden method which calls the various methods. |
Visitor | One or more related classes have the same method, which calls a method specific for themselves in another class. |
Summary
关于设计模式的描述最好还是看英文文档,中文的很多说明都不是很清楚或者说不是很准确,因为中文讲究的是意会,并不是很注重语法和精确性。而设计模式中有些模式之间的差别真的需要仔细甄别才能够体会出来,所以还是建议看英文文档。http://www.fluffycat.com/Java-Design-Patterns/ ↩
相关文章推荐
- PropertyChangeListener简单理解
- 什么是设计模式
- 设计模式之创建型模式 - 特别的变量问题
- 七、设计模式——装饰模式
- 设计模式总结
- 设计模式之创建型模式
- 浅谈设计模式的学习
- Ruby设计模式编程之适配器模式实战攻略
- 实例讲解Ruby使用设计模式中的装饰器模式的方法
- 设计模式中的模板方法模式在Ruby中的应用实例两则
- Ruby设计模式编程中对外观模式的应用实例分析
- 实例解析Ruby设计模式编程中Strategy策略模式的使用
- Ruby中使用设计模式中的简单工厂模式和工厂方法模式
- Ruby使用设计模式中的代理模式与装饰模式的代码实例
- 详解组合模式的结构及其在Ruby设计模式编程中的运用
- C#编程中使用设计模式中的原型模式的实例讲解
- 使用设计模式中的工厂方法模式进行C#编程的示例讲解
- 实例解析C#设计模式编程中简单工厂模式的使用
- 详解C#设计模式编程中生成器模式的使用
- 深入解析C#设计模式编程中对建造者模式的运用