In 1992, Jack Reeves wrote a seminal article in the C++ Journal entitled “What is Software Design?” In this article, Reeves argues that the design of a software system is documented primarily by its source code. 源码就是设计。UML diagrams 也许能够展示一部分设计,但它不是设计的全部。只有源码才是设计。非常推荐这篇文章!!!
Design Smells – The Odors of Rotting Software
- Rigidity – The system is hard to change because every change forces many other changes to other parts of the system. 僵化=难于修改
- Fragility – Changes cause the system to break in places that have no conceptual relationship to the part that was changed. 脆弱=一改就乱
- Immobility – It’s hard to disentangle the system into components that can be reused in other system. 难以提取独立出来
- Viscosity – Doing things right is harder than doing things wrong. 粘滞=做好事难。比如编译时间太长,开发人员就会倾向于修改只需要部分编译的代码,即使这样修改与设计冲突。
- Needless Complexity – The design contains infrastructure that adds no direct benefit. 没必要的复杂=过度设计。我们应该保持设计的flexible,而不是一开始就认为后续会有很多变化,从而把架构写的很复杂。如何保持?看后面介绍的原则,以及测试驱动会驱动你的。
- Needless Repetition – The design contains repeating structures that could be unified under a single abstraction. 重复=滥用粘贴
- Opacity-It’s hard to read and understand. it does not express its intent well.晦涩=代码难懂
What Stimulates the Software to Rot?
主要原因来至需求变化,而且经常要求快速实现需求,导致开发人员写出各种违反原设计的代码,慢慢的Smell就产生了。
然而,我们不能责怪需求的变化。If our designs are failing due the constant rain of changing requirements, it is our designs and practices that are at fault. We must somehow find a way to make our designs resilient to such changes and employ practices that protect them from rotting.