2009年4月14日星期二

对三种模式的理解

昨天提到了在POSA中把模式分为三种,今天继续看,写一点对三种模式的理解。

architectural pattern:An architectural pattern expresses a fundamental structural organi-zation schema for software systems. It provides a set of predefined subsystems, pecifies their responsibilities, and includes rules and guidelines for organizing the relationships between them.
我的理解,architectural pattern为整个软件系统奠定了整体的框架和架构基础,软件系统的框架搭建好后,详细的实现就在这个框架下进行,比如整个软件系统分为几个模块,或者 说几个子系统,每个模块的责任是什么,各个模块之间的关系是什么,把这些厘清后,具体的细节就好实现了。MVC就可以看作是一种 architectural pattern。

design pattern:A design pattern provides a scheme for refining the subsystems or components of a software system, or the relationships between them. It describes a commonly-recumng structure of communicating components that solves a general design problem within a particular context.
我的理解,design pattern比architectural pattern要轻量级,POSA说“Design patterns are medium-scale patterns“,它主要用于模块或者子系统。

idioms:An idiom is a low-level pattern specific to a programming language. An idiom describes how to implement particular aspects of components or the relationships between them using the features of the given language.
我 的理解,这个idioms还不知道怎么翻译,按文中的意思,它是和特定的语音相关的,用特定的语言实现模块的部分功能或者模块间的关联。从这里看出,它比 design pattern又低了一级,它实现更细节的东西。书中举了个例子,就是引用计数,C++用引用计数来管理动态分配的资源,而smalltakl提供了 gc,所以不需要用这种方法。目前对这个idioms还没什么概念,在后面的学习中再领悟吧。

高级别的模式很可能要搭配使用低级别的模 式,书中举了一个例子,就是MVC,它是一个architectural模式,View是处理显示的,Control是处理输入的,Model是做业务处 理的,前两者和后者紧密联系,当业务处理有了新的结果,那么这个结果必须马上被显示处理,必须立即将新的结果通知View,当有用户输入发生时,也必须立 即通知Model进行业务处理。这种情况下,就可以使用design pattern里面的Obeserver模式,定好三者之间的subject和obeserver角色,就可以很好地解决这个问题。各个不同级别的模式经 常要混合使用以达到好的效果,所以Alexander说:Each pattern depends on the smaller patterns it contains and on the larger patterns in which it is contained.

没有评论:

发表评论