Design Metrics CS 406 Software Engineering I Fall





![Depth of inheritance tree [1] z Depth of a class in a class hierarchy Depth of inheritance tree [1] z Depth of a class in a class hierarchy](https://slidetodoc.com/presentation_image_h/0c37cce9741186bb7d4ee0f4b7d5cd4c/image-6.jpg)
![Depth of inheritance tree [2] z In case of multiple inheritance DIT is the Depth of inheritance tree [2] z In case of multiple inheritance DIT is the](https://slidetodoc.com/presentation_image_h/0c37cce9741186bb7d4ee0f4b7d5cd4c/image-7.jpg)











- Slides: 18
Design Metrics CS 406 Software Engineering I Fall 2001 Aditya P. Mathur Last update: October 23, 2001 September 18, 2001 Software Design
Metrics z Metrics are useful in measuring the complexity and “goodness” of a design. z A large number metrics have been proposed for OO designs. z Some of these have been validated experimentally, others are mere proposals or have received little or no validation. September 18, 2001 Software Design 2
Effort z Assumption: The effort in developing a class is determined by the number of methods. z Hence the overall complexity of a class can be measured as a function of the complexity of its methods. Proposal: Weighted Methods per class (WMC) September 18, 2001 Software Design 3
WMC z Let class C have methods M 1, M 2, . . . Mn. z. Let denote the complexity of method z How to measure WMC? September 18, 2001 Software Design 4
WMC: validation z Most classes tend to have a small number of methods, are simple, and provide some specific abstraction and operations. z WMC metric has a reasonable correlation with fault-proneness of a class. September 18, 2001 Software Design 5
Depth of inheritance tree [1] z Depth of a class in a class hierarchy determines potential for re-use. Deeper classes have higher potential for re-use. z Inheritance increases coupling. Changing classes becomes harder. z Depth of Inheritance (DIT) of class C is the length of the shortest path from the root of the inheritance tree to C. September 18, 2001 Software Design 6
Depth of inheritance tree [2] z In case of multiple inheritance DIT is the maximum length of the path from the root to C. z Depth of Inheritance (DIT) of class C is the length of the shortest path from the root of the inheritance tree to C. September 18, 2001 Software Design 7
DIT evaluation z Basili et al. study, 1995. z Chidamber and Kemerer study, 1994. y. Most classes tend to be close to the root. y. Maximum DIT value found to be 10. y. Most classes have DIT=0. y. DIT is significant in predicting error proneness of a class. Higher DIT leads to higher error-proneness. September 18, 2001 Software Design 8
DIT evaluation z Basili et al. study, 1995. z Chidamber and Kemerer study, 1994. • • September 18, 2001 Most classes tend to be close to the root. Maximum DIT value found to be 10. Most classes have DIT=0. DIT is significant in predicting error proneness of a class. Higher DIT leads to higher error-proneness. Software Design 9
Number of children (NOC) z NOC is the number of immediate subclasses of C. z Higher values of NOC suggest reuse of the definitions in the super-class in a larger number of subclasses. z Higher NOC suggests the extent of influence of a class on other elements of a design. Higher influence demands higher quality of that class. September 18, 2001 Software Design 10
Validation of NOC z Classes generally have a small NOC value. z Vast majority have NOC=0. z Larger NOC value is associated with lower probability of detecting faults in that class. September 18, 2001 Software Design 11
Coupling between classes (CBC) z Class C 1 is coupled to class if at least one method of C 1 uses a method or an instance variable of C 2. z Coupling is usually easy to identify though often pointers may make it difficult. z CBC of C=total number of other classes to which C is coupled. September 18, 2001 Software Design 12
Validation of CBC z Most classes are self contained and have CBC=0. z Interface classes tend to have higher CBC values. z CBC is significant in predicting fault-proneness of classes. September 18, 2001 Software Design 13
Response for a class (RFC) z Response set of class C is the total number of methods that can be invoked when a message is sent to an object of C. This includes all methods of C and any methods executed outside of C as a result of this message. z RFC of class C is the cardinality of the response set of C. z Note that even when CBC=1 RFC may be high. This indicates that the “volume” of interaction is high. September 18, 2001 Software Design 14
Validation of RFC z Most classes tend to invoke a small number of methods (low RFC values). z Classes for interface objects tend to have larger RFC values. z RFC is very significant in predicting the faultproneness of a class. September 18, 2001 Software Design 15
Lack of cohesion in methods (LCOM) z Let I 1 and I 2 denote sets of instance variables of methods M 1 and M 2, respectively, in class C. z M 1 and M 2 are considered similar, or cohesive, if I 1 and I 2 are not disjoint. z Let Q be the set of all cohesive method pairs. z Let P be the set of all non-cohesive method pairs. z LCOM=|P| - |Q| if |P| > |Q|, 0 otherwise. September 18, 2001 Software Design 16
LCOM z A larger number of cohesive pairs implies smaller LCOM. z A high value of LCOM suggests that a class is trying to support multiple abstractions. Perhaps the class needs to be partitioned into smaller and more cohesive classes. z LCOM is found to be not very significant in predicting fault-proneness. September 18, 2001 Software Design 17
Summary z. What are OO metrics? z. Metrics for complexity, coupling, and cohesion September 18, 2001 Software Design 18