7/29/2019 Software Metrics Lec011
1/29
Software Metrics (SEN-630)Master of
Software Engineering
Dr. Syed Asif AliHead of Computer Science
Department Bahria University
7/29/2019 Software Metrics Lec011
2/29
Quality Model
product
operation revision transition
reliability efficiency usability maintainability testability portability reusability
Metrics
7/29/2019 Software Metrics Lec011
3/29
High level Design Metrics
Structural Complexity
Data Complexity
System Complexity
Card & Glass 80
Structural Complexity S(i) of a module i.
S(i) = fout2(i)
Fan out is the number of modules immediately
subordinate (directly invoked).
7/29/2019 Software Metrics Lec011
4/29
Design Metrics
Data Complexity D(i)
D(i) = v(i)/[fout(i)+1]
v(i) is the number of inputs and outputs
passed to and from i
System Complexity C(i)
C(i) = S(i) + D(i)As each increases the overall complexity of
the architecture increases
7/29/2019 Software Metrics Lec011
5/29
System Complexity Metric
Another metric:
length(i) * [fin(i) + fout(i)]2
Length is LOC
Fan in is the number of modules that invoke i
Graph based:
Nodes + edges Modules + lines of control
Depth of tree, arc to node ratio
7/29/2019 Software Metrics Lec011
6/29
Coupling
Data and control flow di input data parameters
ci input control parameters
do output data parameters
co output control parameters
Global gd global variables for data
gc global variables for control
Environmental w fan in
r fan out
7/29/2019 Software Metrics Lec011
7/29
Metrics for Coupling
Mc = k/m, k=1
m = di + aci + do + bco + gd + cgc + w + r
a, b, c, k can be adjusted based on actual
data
7/29/2019 Software Metrics Lec011
8/29
Component Level Metrics
Cohesion (internal interaction) - a function of dataobjects
Coupling (external interaction) - a function of input and
output parameters, global variables, and modules called
Complexity of program flow - hundreds have beenproposed (e.g., cyclomatic complexity)
Cohesion difficult to measure Bieman 94, TSE 20(8)
7/29/2019 Software Metrics Lec011
9/29
Using Metrics
The Process Select appropriate metrics for problem
Utilized metrics on problem
Assessment and feedback
Formulate
Collect
Analysis Interpretation
Feedback
7/29/2019 Software Metrics Lec011
10/29
Metrics for the Object Oriented
Chidamber & Kemerer 94 TSE 20(6)
Metrics specifically designed to addressobject oriented software
Class oriented metrics
Direct measures
7/29/2019 Software Metrics Lec011
11/29
Weighted Methods per Class
WMC =
ci is the complexity (e.g., volume, cyclomaticcomplexity, etc.) of each method
Viewpoints: (of Chidamber and Kemerer)
-The number of methods and complexity of methods is an indicator
ofhow much t ime and effor t is required to develop andmaintainthe object
-The larger the number of methodsin an object, the greater thepotentialimpact on the chi ldren
-Objects with large number of methodsare likely to be more
application specific, l imit ing the poss ible reuse
n
i
ic1
7/29/2019 Software Metrics Lec011
12/29
Depth of Inheritance Tree
DIT is the maximum length from a node to
the root (base class)
Viewpoints: Lower level subclasses inherit a number of methods
making behavior harder to predict
Deeper trees indicate greater design complexity
7/29/2019 Software Metrics Lec011
13/29
Number of Children
NOC is the number of subclasses immediatelysubordinate to a class
Viewpoints: As NOC grows, reuse increases - but the abstraction may be diluted
Depth is generally betterthan breadth in class hierarchy, since itpromotes reuse of methods through inheritance
Classes higher up in the hierarchyshould have more sub-classesthen those lower down
NOC gives an idea of the potential influence a class has on thedesign: classes with large number of children may require moretesting
7/29/2019 Software Metrics Lec011
14/29
Coupling between Classes
CBO is the number of collaborations
between two classes (fan-out of a class C) the number of other classes that are referenced in the
class C (a reference to another class, A, is anreference to a method or a data member of class A)
Viewpoints: As collaboration increases reuse decreases
High fan-outs represent class coupling to other classes/objects and
thus are undesirable
High fan-ins represent good object designs and high level of reuse
Not possible to maintain high fan-in and low fan outs across the
entire system
7/29/2019 Software Metrics Lec011
15/29
Response for a Class
RFC is the number of methods that could be
called in response to a message to a class (local
+ remote)
Viewpoints:
As RFC increases
testing effort increases greater the complexity of the object
harder it is to understand
7/29/2019 Software Metrics Lec011
16/29
Lack of Cohesion in Methods
LCOM poorly described in Pressman
Class Ckwith n methods M1,Mn
Ij is the set of instance variables used by
Mj
7/29/2019 Software Metrics Lec011
17/29
LCOM
There are n such sets I1,, In
P= {(Ii, Ij) | (IiIj) = }
Q = {(Ii, Ij) | (IiIj) }
If all n sets Iiare then P=
LCOM = |P| - |Q|, if |P| > |Q| LCOM = 0 otherwise
7/29/2019 Software Metrics Lec011
18/29
Example LCOM
Take class Cwith M1, M2, M3 I1 = {a, b, c, d, e}
I2= {a, b, e}
I3 = {x, y, z}
P= {(I1, I3), (I2, I3)}
Q = {(I1, I2)}
Thus LCOM = 1
7/29/2019 Software Metrics Lec011
19/29
Explanation
LCOM is the number of empty intersectionsminus the number of non-empty intersections
This is a notion of degree of similarity ofmethods
If two methods use common instance variablesthen they are similar
LCOM of zero is not maximally cohesive
|P| = |Q| or |P| < |Q|
7/29/2019 Software Metrics Lec011
20/29
Class Size
CS
Total number of operations (inherited, private,
public)
Number of attributes (inherited, private,
public)
May be an indication of too muchresponsibility for a class
7/29/2019 Software Metrics Lec011
21/29
Number of Operations Overridden
NOO
A large number for NOO indicatespossible problems with the design
Poor abstraction in inheritance hierarchy
7/29/2019 Software Metrics Lec011
22/29
Number of Operations Added
NOA
The number of operations added by asubclass
As operations are added it is farther away
from super class As depth increases NOA should decrease
7/29/2019 Software Metrics Lec011
23/29
Method Inheritance Factor
MIF = .
Mi(Ci) is the number of methods inheritedand not overridden in Ci
Ma(Ci) is the number of methods that can
be invoked with Ci Md(Ci) is the number of methods declared
in Ci
n
i
ia
n
i
ii
CM
CM
1
1
)(
)(
7/29/2019 Software Metrics Lec011
24/29
MIF
Ma(Ci) = Md(Ci) + Mi(Ci)
All that can be invoked = new or
overloaded + things inherited
MIF is [0,1]
MIF near 1 means little specialization MIF near 0 means large change
7/29/2019 Software Metrics Lec011
25/29
Coupling Factor
CF= .
is_client(x,y) = 1 iff a relationship exists betweenthe client class and the server class. 0otherwise
(TC2-TC) is the total number of relationshipspossible
CF is [0,1] with 1 meaning high coupling
)(
),(_2 TCTC
CCclientisi j ji
7/29/2019 Software Metrics Lec011
26/29
Polymorphism Factor
PF = .
Mn() is the number of new methods
Mo() is the number of overriding methods
DC() number of descendent classes of a base class
The number of methods that redefines inherited methods, divided bymaximum number of possible distinct polymorphic situations
i iin
i io
CDCCM
CM
)()(
)(
7/29/2019 Software Metrics Lec011
27/29
Operational Oriented Metrics
Average operation size (LOC, volume)
Number of messages sent by an operator
Operation complexity cyclomatic
Average number of parameters/operation Larger the number the more complex the
collaboration
7/29/2019 Software Metrics Lec011
28/29
Encapsulation
Lack of cohesion
Percent public and protected
Public access to data members
7/29/2019 Software Metrics Lec011
29/29
Inheritance
Number of root classes
Fan in multiple inheritance
Top Related