1可维护性的常见度量指标
⇒圈复杂度: structural complexity
⇒number of different code paths in the flow of the program .
⇒代码行数
⇒ Maintainability Index (MI)可维护指数:0~100越高越好
⇒Halstead Volume (HV)
⇒ Cydomattc Complexity (CC)
⇒ The average number of lines of code per module (LOC)
⇒ The percentage of comment lines per module
⇒ Depth of inheritance 继承的层数
⇒ Class Coupling 类之间的耦合度
⇒ Unit test coverage
2.聚合度和耦合度
⇒耦合度:the measure of dependency between modules . A dependency exists between two modules if a change in one could require a change in the other.
⇒一个被改了,另一个也要跟着改
⇒被interfaces between modules和 Complexity of each interface所度量
⇒聚合度: meature how strong related the functions or responsibilities of a module are .
⇒ a module has high cohesion if all of its elements are working towards the same goal
⇒好的模块化编程:高内聚,低耦合
⇒ high cohesion within modules
⇒ Loose coupling between modules
3.SOLID
⇒SOLID:5个class的设计原则
⇒ SRP : The Single Responsibility Principle单一责任原则
⇒ OCP : Open-Close Principle开放-封闭原则
⇒ LSP : Liskov Substitution Principle Liskove 替换原则
⇒ DIP : Dependency Inversion Principle依赖转置原则
⇒ ISP : Interface Segregation Principle接口聚合原则
⇒ SRP : 单一责任原则
⇒责任:变化的原因
⇒不应有多于1个的原因使得一个类发生变化
⇒ OCP : 开放-封闭原则
⇒对扩展性开放:模块的行为应是可扩展的,从而该模块可表现出新的行为以满足需求的变化
⇒对修改封闭:
模块自身的代码是不应被修改的
扩展模块行为的一般途径是修改模块的内部实现
如果一个模块不能被修改,那么通常被认为是具有固定行为的
⇒关键解决方案:抽象技术,通过inheritance和composition来改变一个类的行为
⇒ LSP : Liskove 替换原则
⇒子类型必须可以替换其基类型
⇒派生类必须能够通过其基类的接口使用,客户端无需了解二者之间的差异
⇒DIP依赖专制原则
⇒高层次模块不应依赖于低层次模块,二者都依赖于抽象模块
⇒抽象模块不应依赖具体模块,具体应依赖于抽象
⇒ISP:接口聚合原则
⇒客户端不应依赖于它们不需要的方法
⇒”胖“接口有很多缺点,不够聚合
⇒可以分解为多个小接口
⇒不同的接口向不同的客户端提供服务
⇒客户端只访问自己需要的接口