设计模式学习笔记一

类别:编程语言 点击:0 评论:0 推荐:

设计模式学习笔记一

1.为什么需要设计模式:

    设计模式是一个可变的,可重用的elegant的软件解决方案。程序员使用设计模式可以在软件设计中更好的组织对象,利于软件的编写和修改。(也就是使软件有个好的架构,扩展性好)。设计模式是和面向对象紧密联系的。我们使用模式的基本原因就使为了各个类之间隔离开,每个类很少知道其他类的内部实现(低耦合,有利于扩展),同时还要方便每个类之间的信息交互。

 

2.设计模式的定义:

·         Design patterns are recurring solutions to design problems you see over and over. (The Smalltalk Companion)

·         Design patterns constitute a set of rules describing how to accomplish certain tasks in the realm of software development. (Pree 1995)

·         Design patterns focus more on reuse of recurring architectural design themes, while frameworks focus on detailed design and implementation. (Coplien and Schmidt 1995)

·         A pattern addresses a recurring design problem that arises in specific design situations and presents a solution to it. (Buschmann et al. 1996)

·         Patterns identify and specify abstractions that are above the level of single classes and instances or of components. (Gamma, Johnson, and Vlissides, 1993)

  模式本来就是一种解决问题的方法或者途径。就好像我们要去篮球场打球,我们可以直接去,也可以绕主楼一圈再去,当然还有许多其他的途径。每一种去球场的路径都可以称之为一种模式(都达到了我们去球场的目的),不过这里面有最简单的(直接去),也有最麻烦的(绕路去), 设计模式就是让我们如何选择出最优,最简单的解决问题的方法。

 

3.设计模式是仅仅关于对象的设计的么?

  设计模式不仅仅是关于对象的设计,它还包括对象之间交互的设计。

 

4.设计模式是语言无关的么??

   设计模式是一种解决问题的方法。从思想的角度来说,设计模式是语言无关。但是对于不同的语言,由于语言之间的差异性,实现某一种模式,每一种语言都有表现的不相同,所以从语言实现的角度,设计模式还是语言相关的。

 

5.面向接口编程,而不要面向实现编程

本文地址:http://com.8s8s.com/it/it26579.htm