天天看点

软件开发中的设计原则软件开发中的设计原则参考

软件开发中的设计原则

基础原则

SOLID在面向对象的软件开发中是一组非常出名的设计原则之一。它是下面五项原则的首字母集合,你可以通过SOLID来快速记忆它们。

  • Single Responsibility Principle(SPR)单一职责原则
  • Open/Closed Principle(OCP)开闭原则
  • Liskov Substitution Principle(LSP)里氏替换原则
  • Interface Segregation Principle(ISP)接口隔离原则
  • Dependency Inversion Principle (DIP)依赖倒置原则

SOLID的作者Robert C. Marti认为时代在变化,但是DOLID设计五原则是不变且不过时的。因为自从1945年图灵在电子计算机上写下第一行代码开始,软件就未怎么改变,大行其道的仍然是

if

语句、

while

循环和赋值声明 — 序列、选择和迭代:

The SOLID principles remain as relevant to day as they were in the 90s (and indeed before that). This is because software hasn’t changed all that much in all those years — and that is because software hasn’t change all that much since 1945 when Turing wrote the first lines of code for an electronic computer.

Software is still if statements, while loops, and assignment statements — Sequence, Selection, and Iteration.

补充原则

除了著名的SOLID五原则之外,我还从不同角度分析,认为下面三项原则也应当被引入应用程序设计中,作为你的设计与开发的指导和方向:

  • Composite Reuse Principle (CRP) 合成复用原则
  • Low Knowledge Principle (LKP) 最少知道原则
  • Least Priority Principle (LPP) 最小权限原则

我将在接下来的一系列文章中对这七项原则进行逐一进行解释。

参考

  • SOLID Relevance

继续阅读