软件开发的经典法则
康威定律⌗
Any organization that designs a system (defined more broadly here than just information systems) will inevitably produce a design whose structure is a copy of the organization’s communication structure. - Melvin Conway
设计系統的架构受制于产生这些设计的组织的沟通结构。”通俗的来讲:产品必然是其(人员)组织沟通结构的缩影。 康威定律可总结为四个定律:
- 组织沟通方式会通过系统设计表达出来。
- 时间再多一件事情也不可能做的完美,但总有时间做完一件事情。
- 线型系统和线型组织架构间有潜在的异质同态特性。
- 大的系统组织总是比小系统更倾向于分解。
SOLID原则⌗
1 Single Responsibility Principle 单一职责原则⌗
There should never be more than one reason for a class to change.
一个类应该只有一个发生变化的原因
2 Open Closed Principle 开闭原则⌗
Software entities like classes, modules and functions should be open for extension but closed for modification.
一个软件实体,如类、模块和函数应该对扩展开放,对修改关闭
3 Liskov Substitution Principle 里氏替换原则⌗
Functions that use use pointers or references to base classes must be able to use objects of derived classes without knowing it.
所有引用基类的地方必须能透明地使用其子类的对象
4 Law of Demeter 迪米特法则⌗
Talk only to your immediate friends and not to strangers.
如果两个软件实体无须直接通信,那么就不应当发生直接的相互调用,可以通过第三方转发该调用。其目的是降低类之间的耦合度,提高模块的相对独立性。
5 Interface Segregation Principle 接口隔离原则⌗
Clients should not be forced to depend upon interfaces that they don`t use. The dependency of one class to another one should depend on the smallest possible.
- 客户端不应该依赖它不需要的接口。
- 类间的依赖关系应该建立在最小的接口上。
6 Dependence Inversion Principle 依赖倒置原则⌗
High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.
- 上层模块不应该依赖底层模块,它们都应该依赖于抽象。
- 抽象不应该依赖于细节,细节应该依赖于抽象。
清晰原则⌗
Programs must be written for people to read, and only incidentally for machines to execute. - Hal Abelson and Gerald Sussman
程序必须是为了开发人员阅读而编写的,只是偶尔给机器去执行,99%的时间程序代码面向的是开发人员,而只有1%的时间可能是机器在执行。
Simplicty 简单原则⌗
Simplicity is prerequisite for reliability. - Edsger W. Dijkstra
简单是可靠的前提。