Skip to content

SOLID

wikipedia SOLID

Concepts

Single responsibility principle

单一职能原则

a class should have only a single responsibility (i.e. changes to only one part of the software's specification should be able to affect the specification of the class).

NOTE: Unix philosophy中有一条为: Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new "features". Mike Gancarz所著的《Linux and the Unix Philosophy》也对该哲学进行了解释。

现在对比来看,其实这两种思想是契合的。

Open/closed principle

闭开原则

"software entities … should be open for extension, but closed for modification."

Liskov substitution principle

里氏替换原则

"objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program." See also design by contract.

Interface segregation principle

"many client-specific interfaces are better than one general-purpose interface."

Dependency inversion principle

one should "depend upon abstractions, [not] concretions."

NOTE: 其实和OOP的“program to an abstraction not implementation"一致

深入理解

上述罗列了五大设计原则,但是并没有深入,下面这些是原文的**References**中给出的列表中,我发现的一些比较有价值的内容:

Robert C. Martin. "Principles Of OOD". butunclebob.com. Retrieved 2014-07-17.. (Note the reference to “the first five principles”, though the acronym is not used in this article.) Dates back to at least 2003.

butunclebob The Principles of OOD

两个 inversion

在面向对象编程的SOID原则中有Dependency inversion principle,即依赖反转;另外一个inversion是: Inversion of control ,在工程software-engineering的Software-design\Control-theory\Inversion-of-control章节中对它进行了描述。