SOLID (computer programming)

最近要准备一份 design pattern 的ppt,于是网上找了一圈相关的材料,最后发现比起构造性的design来说,我还是更喜欢限制性的principle。因为一般而言,principle的条目数量要少。当然,design的优点是其指导性和参考性。

SOLID 就是 Single responsibility, Open-closed, Liskov substitution, Interface segregation 和 Dependency inversion。
Single responsibility,即对象只有唯一的职责。
Open-closed,即对象对于应易于扩展而言应为开放的,而对于修改应为关闭的。
Liskov substitution,即父类型应可以用其子类型替换,而不影响程序的正确性。这里的“正确”是语义性的。
Interface segregation,就是接口的隔离和专门化。
Dependency inversion,就是高阶模块只应依赖于低阶模块的抽象接口,而非其具体实现。
总的来说 SOLID 可以作为一定程度上的指导性条件来参考了。即使是作为理论,L这条也太过严格了点。

相关的还有GRASPDRY(Don’t repeat yourself)就不用再说了吧。

Advertisements
This entry was posted in Computer and Internet, Programming and Algorithm. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s