240 likes | 408 Views
Metrics. Traditional. Object-Oriented. Fan-in/fan-out. Weighted methods per class. Lines of code. Response for a class. Cyclomatic complexity. Lack of cohesion of methods. Comment percentage. Coupling between objects. Length of identifiers. Depth of inheritance tree.
E N D
Metrics Traditional Object-Oriented Fan-in/fan-out Weighted methods per class Lines of code Response for a class Cyclomatic complexity Lack of cohesion of methods Comment percentage Coupling between objects Length of identifiers Depth of inheritance tree Depth of conditional nesting Number of children Fog index Number of overriding operations Traditional metrics can be applied to OO environments too see http://satc.gsfc.nasa.gov/support/STC_APR98/apply_oo/apply_oo.htm 91.3913 R. McFadyen
Traditional Metrics Fan-in/fan-out Fan-in is a measure of the number of functions that call some other function, say X Fan-out is a measure of the number of functions which are called by a function, say X. (See RFC) Cyclomatic complexity CC is a count of the number of test cases required to test comprehensively 91.3913 R. McFadyen
Traditional Metrics Lines of Code • LOC can be counted as • lines (LOC) • non-comment non-blank lines (NCNB) • executable statements (EXEC) • Note that NASA uses executable lines of code to evaluate size Comment percentage Calculated as the total number of comments divided by the {total lines of code less the number of blank lines} 91.3913 R. McFadyen
Traditional Metrics Depth of conditional nesting Measure of the depth of nesting of IF statements in programs Length of identifiers Measures average length of distinct identifiers Fog index Measure of the average length of words and sentences in documents. The higher the value for the Fog index, the more difficult ... 91.3913 R. McFadyen
OO Metrics Weighted methods per class WMC is the number of methods included in a class weighted by the complexity of each method Response for a class RFC is a count of all methods that can be invoked in response to a message to an object of the class 91.3913 R. McFadyen
OO Metrics Lack of cohesion of methods LOCM measures the dissimilarity of methods in a class. A highly cohesive module stands alone. Lack of cohesion increases complexity. Coupling between objects CBO is a count of the number of other classes to which a class is coupled. Measured by counting the number of distinct non-inheritance related class hierarchies on which a class depends 91.3913 R. McFadyen
OO Metrics Depth of inheritance tree DIT is the maximum number of steps from the class node to the root of the tree Number of children NOC is the number of immediate subclasses subordinate to a class in the hierarchy Number of overriding operations Number of operations in a superclass that are overridden in a subclass 91.3913 R. McFadyen
WMC Weighted methods per class WMC is the number of methods included in a class weighted by the complexity of each method How does one count this? a) simply count the number of methods, or, b) sum the complexities of the methods (complexity might be rated: 1 Simple, 2 Moderately complex, 3 Complex) 91.3913 R. McFadyen
WMC Shows that most classes have less than 20 methods, … but some have over 200 methods. 91.3913 R. McFadyen
RFC Response for a class RFC is a count of all methods that can be invoked in response to a message to an object of the class How does one count this? For a class, we count the number of distinct methods that can be invoked in response to a message, including all methods within the class hierarchy For a class, we count all messages that can be sent by all methods in the class 91.3913 R. McFadyen
RFC In this case, about half the classes have an RFC <=20 91.3913 R. McFadyen
LCOM Lack of cohesion of methods LOCM measures the dissimilarity of methods in a class. A highly cohesive module stands alone. Lack of cohesion increases complexity. • How does one count this? • We need a way of measuring cohesiveness (or not). • Possibilities: • a) compute the average over all attributes in a class • number of methods using the attribute • total number of methods • convert to a percentage and subtract from 100 91.3913 R. McFadyen
LCOM Possibilities (continued): b) for each method, create a set of the attributes it accesses. For each pair of methods, perform the intersection of attributes. If an intersection is not empty put the set in P; if it is empty put the set in Q. The measure is the difference in cardinalities of P and Q: LCOM = P - Q if P > Q otherwise LCOM = 0 91.3913 R. McFadyen
LCOM 91.3913 R. McFadyen
CBO Coupling between objects CBO is a count of the number of other classes to which a class is coupled. Measured by counting the number of distinct non-inheritance related class hierarchies on which a class depends • How does one count this? • count the number of distinctnoninheritance-related class hierarchies on which a class depends 91.3913 R. McFadyen
CBO A CBO value of zero corresponds to a class that is only coupled to others in its related inheritance hierarchy 91.3913 R. McFadyen
DIT DIT is the maximum number of steps from the class node to the root of the tree Depth of inheritance tree Most classes are at level 0 and 1 91.3913 R. McFadyen
NOC Number of children NOC is the number of immediate subclasses subordinate to a class in the hierarchy • How does one count this? • the number of immediate subclasses subordinate to a class in the hierarchy 91.3913 R. McFadyen
NOC One of these classes, at depth 3, has almost 40 children! 91.3913 R. McFadyen
CC Cyclomatic complexity CC is a count of the number of test cases required to test comprehensively CC measures the amount of decision logic in a module. A value of 10 or less is the general recommendation. 91.3913 R. McFadyen
CC 91.3913 R. McFadyen
CC 91.3913 R. McFadyen
Assignment 4 • Due in class April 3, 2002 • 4 questions: • For the code on pages 313-316, • 1. Illustrate the complexity graph and determine the CC for getTotal() • 2. Determine the WMC for Sale, SalesLineItem, and ProductSpecification • - use WMC technique a) • 3. Determine the LCOM for ProductSpecification and SalesLineItem • - use LCOM technique a) 91.3913 R. McFadyen
Assignment 4 • 4. Based on Figures 20.11 and the code on pages 313-316, design an object to relational mapping for Sale, SalesLineItem, and ProductSpecification. • Illustrate the Sale, SalesLineItem, ProductSpecification rows that would exist given the test data at the bottom of Page 312. 91.3913 R. McFadyen