设计模式是从那些最基本的软件开发原则(比如OCP,LSP,DIP等)发展而来的,只是这些原则在特定情况下的最佳实践。实际情况千变万化,只有基本的原则才是永恒不变的,常用的24种设计模式只是对于原则实践的24个例子。由基本原则发展出来的还有架构模式,他和设计模式其实没有本质上的区别,只是关注的高度不同而已。
SSH,总的来看,在一定程度上实现了组件之间的解耦,也是基本原则的一个出色的实践。不过因为它解决问题的层次更高,所以是架构模式(architectural pattern)。
感觉在SSH中用不上设计模式,正反应了SSH架构的优秀。之所以这么说是因为设计模式的实现,是为了解决特定的问题(大部分是解耦)而写的代码,往往是多余的(就算没有,当前的程序也可以运行的很好),而在SSH中,我们不需要写多余的模式代码,同样可以达到相同的目的。举个例子来说,如果没有Spring的话,我们可能需要自己写很多的Factory来解耦(在没有用Spring以前我就是这么做的)。有了Spring,我们只需要定义接口,写纯业务代码就可以了,解耦的问题容器已经给解决了。
最后贴一段wiki里design pattern的定义:
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Algorithms are not thought of as design patterns, since they solve computational problems rather than design problems.
Not all software patterns are design patterns. Design patterns deal specifically with problems at the level of software design. Other kinds of patterns, such as architectural patterns, describe problems and solutions that have alternative scopes.