面向对象编程的SOLID原则

SOLID原则(单一职责,开放封闭,里氏替换,接口隔离和依赖反转)是面向对象编程和设计的五项基本原则。目标是创建一个系统,很容易维护和扩展。

S代表SRP:
Single responsibility principle 单一职责原则
a class should have only a single responsibility. 一个类应该只有一个单一的职则

O代表OCP
Open/closed principle 开放封闭原则
“software entities … should be open for extension, but closed for modification”. 软件个体应该对扩展开放,而禁止对内部的修改

L代表LSP
Liskov substitution principle 里氏替换原则
“objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program”. 程序对象应该可以被它的子类实例替换,而不失正确性

I代表ISP
Interface segregation principle 接口隔离原则
“many client-specific interfaces are better than one general-purpose interface.” 多个专门的接口优于多合一的接口

D代表DIP
Dependency inversion principle 依赖反转原则
one should “Depend upon Abstractions. Do not depend upon concretions.” 不同级别的模块之间的依赖应该在于抽象,而不是具体

Link: http://en.wikipedia.org/wiki/Solid_%28object-oriented_design%29