Subhas C. Misra and Virendrakumar C. Bhavsar
Following are the descriptions of the different metrics.
Average class size (ACLOC): This is the average class size in terms of the number of lines per class. In other words, it provides an indication of the average lines of code contained in each class in a project.
Average class size = (Total number of lines of code) / (The number of classes)
Attribute hiding factor (AHF): This is the measure of the invisibilities of attributes in classes. The invisibility of an attribute refers to the percentage of the total classes from which the attribute is invisible. It can be calculated by summing the invisibility of each attribute with respect to the other classes in the project. In the previous calculation of invisibility, private=1, public=0, protected = Size of the inheritance tree / Number of classes. AHF is a fraction.
Attribute hiding factor = (Sum of the invisibilities of all attributes defined in all classes) / (Total number of attributes defined in the project)
Attribute inheritance factor (AIF): This is the fraction of class attributes that are inherited. The expression for calculating it requires summing the inherited attributes for all classes from its super-classes in a project. Attribute inheritance factor = (Sum of inherited attributes) / (Total number of available attributes)
Average method size (AMLOC): This is the average method size in terms of number of lines per method (Lorenz and Kidd 1994). AMLOC metric provides an indication as to the average lines of code in a method in a project.
Average method size = (The total number of lines of code) / (The number of methods)
Average depth of paths (AVPATHS): This is the average depth of paths from methods that have paths to begin with.
Average depth of paths = (The number and size of all paths from all methods) / (The number of methods that have other method calls)
Control density (CDENS): This represents the fraction of control statements in the code. It is obtained by calculating the following expression:
Control density = (The number of control statements) / (The total number of statements)
Coupling factor (COF): COF measures the extent of communication between client and supplier classes. It is measured for the entire project as the fraction of the total possible class coupling.
Coupling factor = (Number of noninheritance couplings) / (Maximum number of couplings in a system)
The maximum number of couplings includes both inheritance-based couplings and noninheritance-based couplings. The inheritance-based couplings occur when subclasses inherit attributes and methods from its super-class. The value of the coupling factor is between 0 and 1. Lower values are better than higher ones.
Depth of inheritance tree (DIT): DIT (Chidamber and Kemerer 1994) measures the position of a class in the inheritance tree. It corresponds to the level number of a class in the inheritance hierarchy. The root class has a DIT value of zero. Within an inheritance hierarchy, the depth of a class refers to the maximum length from the class node to the root of the class hierarchy tree; depth of a class = number of ancestor classes. In the cases of multiple inheritance, DIT = maximum length from the node to the root of the tree.
Lack of cohesion in methods (LOCM): LOCM metrics calculates the degree of communication between the methods and member variables of a class. It is obtained by calculating a list of member variables and the number of references to each variable of all methods in that class. Secondly, the sum of the ratios of the usage, divided by the total number of methods, is obtained. Finally, LOCM is calculated as the quotient of the sum of ratios by the total number of attributes.
Method hiding factor (MHF): MHF is the measure of the invisibilities of methods in classes. The invisibility of a method refers to the percentage of the total classes from which the method is invisible. It can be calculated by summing the invisibility of each method in respect to the other classes in the project. In the previous calculation, private=1, public=0, protected = Size of the Inheritance tree / Number of classes. MHF is a fraction.
Method hiding factor = (Sum of the invisibilities of all methods defined in all classes) / (Total number of methods defined in the project)
Method inheritance factor (MIF): This is obtained by dividing the total number of inherited methods by the total number of methods. The total number of inherited methods is obtained by summing the number of operations that a class has inherited from its super-classes.
Method inheritance factor = (Sum of inherited methods) / (Total number of inherited methods)
Program vocabulary (n): The metric n measures the total number of unique operators and operands in a piece of code (Halstead 1977). The terminology unique refers to the distinct operators and operands only in the count. If A + B is an operation, A and B are said to be operands while + is said to be an operator. Common examples of operators include + > >= < <= << >> || |= & && &= % %= / ++ += -=.
Program length (N): The metric N stands for the program length (Halstead 1977). Program length represents the total count of occurrences of all operators and operands occurring in an implementation.
Number of classes (NCLASS): This calculates the total number of classes. A class is a basic unit of OO designs that consists of data members (or variables) and methods that describe the behavior of a class.
Number of methods (NMETH): It calculates the total number of methods. In purely OO programs, methods are encapsulated inside classes.
Polymorphism factor (POF): This is used to measure the extent
to which classes within a project are polymorphic (Brite e Abreau and
Carapuca 1994). Polymorphism is used in OO programming to perform run-time
binding to one class among several other classes in the same hierarchy
of classes. Polymorphism helps in processing instances of classes according
to their data type or class. Polymorphism factor = (Actual number of different
polymorphic situations) / (Maximum number of possible different polymorphic
situations, that is, extreme situation where all methods were overridden
in all classes, except the base class).
Percentage public/protected members (PPPC): This calculates the percentage of public and protected members of a class with respect to all members of the class. Public data members are those that can be accessed by any code, which can access an object without any restriction. Protected members can be accessed from the class that contains the member and all other subclasses derived from it.
Response for classes (RFC): RFC measures the cardinality of the response set of a class (Chidamber and Kemerer 1994). Response for class = (The number of methods in a class) + (The number of distinct methods called by those methods)
Since the principal mode of communication between objects is through
message passing, an object can be made to act in a certain way through
a particular way of method invocation.
Source lines of code (SLOC): This is the number of source lines in the project, excluding lines with white spaces and comments.
Weighted methods in classes (WMC): This reflects the complexity of the classes and is the sum of the cyclomatic complexities of all methods in the classes (Chidamber and Kemerer 1994). Thus, WMC = Sum of McCabes Cyclomatic Complexity of all local methods. In a flowgraph, McCabes Cyclomatic Complexity is calculated by the following expression:
(Number of edges) (Number of nodes) + 1.