面向对象编程类型的项目的度量

 

面向对象编程类型的项目的度量

 

摘自Stephen H . Kan 的《Metrics and Models in Software Quality Engineering Chapter 12. Metrics and Lessons Learned for Object-Oriented Projects

 

 

Table 12.1.. OO Metrics and Rules of Thumb Recommended by Lorenz (1993)

Metric

Rules of Thumb and Comments

1. Average Method Size (LOC)

方法的平均代码行数

Should be less than 8 LOC for Smalltalk and 24 LOC for C++

对于Smalltalk,应该小于8 行,对于C++应小于24行

2. Average Number of Methods per Class

每个类中拥有的方法的平均个数

Should be less than 20. Bigger averages indicate too much responsibility in too few classes.

应该小于20个。太多意味着用太少的类去实现太多的内容,每个类的职责过多了。

3. Average Number of Instance Variables per Class

每个类中的实例变量的平均个数

Should be less than 6. More instance variables indicate that one class is doing more than it should.

应该小于6个。太多的实例变量意味着类做了很多它不应该做的事情。

4. Class Hierarchy Nesting Level (Depth of Inheritance Tree, DIT)

类嵌套的层次(继承的深度)

Should be less than 6, starting from the framework classes or the root class.

应该小于6,从框架类或基类开始数起。

5. Number of Subsystem/Subsystem Relationships

子系统/子系统间关系的个数

Should be less than the number in metric 6.

应该小于第6点所度量出来的数字。

6. Number of Class/Class Relationships in Each Subsystem

每个子系统中,类/类间关系的个数

Should be relatively high. This item relates to high cohesion of classes in the same subsystem. If one or more classes in a subsystem don't interact with many of the other classes, they might be better placed in another subsystem.

该值应该比较高。该值与子系统中的类的高类聚性有直接关系。如果子系统中的一个或多个类与其他很多的类没有交互,那么它们或许应该放到其它的子系统中。

7. Instance Variable Usage

实例变量的使用

If groups of methods in a class use different sets of instance variables, look closely to see if the class should be split into multiple classes along those "service" lines.

如果类中的一些方法分别使用了几组的实例变量,那么应该仔细分析类是否应该按一定的界线去分割成若干个类。

8. Average Number of Comment Lines (per Method)

注释行的平均个数(对于每个方法而言)

Should be greater than 1.

应该大于1.

9. Number of Problem Reports per Class

对于每个类所发现的问题

Should be low (no specifics provided).

没有具体的值,但是应该比较低

10. Number of Times Class Is Reused

类被重用的次数

If a class is not being reused in different applications (especially an abstract class), it might need to be redesigned.

如果类(尤其是抽象类)没有在不同的应用程序中重用的 ,那么很可能需要对这些类进行重新设计。

11. Number of Classes and Methods Thrown Away

类或方法被抛弃不用的个数

Should occur at a steady rate throughout most of the development process. If this is not occurring, one is probably doing an incremental development instead of performing true iterative OO design and development.

在大部分的开发过程中,类或方法应该按一定的比率抛弃。如果不怎么抛弃所写的类或方法的话,那么可能是在用增量的开发方式,而不是在用真正的OO设计进行迭代开发。

Source: Lorenz, 1993.

 

 

你可能感兴趣的:(面向对象编程类型的项目的度量)