Software Metrics

26
Software Metrics Software Metrics Mei-Huei Tang Mei-Huei Tang October 25, 2000 October 25, 2000 Computer Science Computer Science Department Department SUNY Albany SUNY Albany

description

Software Metrics. Mei-Huei Tang October 25, 2000 Computer Science Department SUNY Albany. Software Metrics. Units of measurement Characterize essential features of software quantitatively. Software products, Software processes, and Software people. - PowerPoint PPT Presentation

Transcript of Software Metrics

Page 1: Software Metrics

Software MetricsSoftware Metrics

Mei-Huei TangMei-Huei Tang

October 25, 2000October 25, 2000

Computer Science DepartmentComputer Science Department

SUNY AlbanySUNY Albany

Page 2: Software Metrics

Software MetricsSoftware Metrics

Units of measurementUnits of measurement Characterize essential features of software quantitatively.Characterize essential features of software quantitatively.

• Software products, Software products,

• Software processes, andSoftware processes, and

• Software people.Software people.

Quantitative measures, enable gaining insight ofQuantitative measures, enable gaining insight of efficiency of software process,efficiency of software process, productivity and quality of software projectproductivity and quality of software project

Characterize, evaluate, predict, and improve.Characterize, evaluate, predict, and improve.

Page 3: Software Metrics

Software Metrics CategoriesSoftware Metrics Categories

Generally software metrics can be divided Generally software metrics can be divided into two categoriesinto two categories

Project Metrics (Process Metrics)Project Metrics (Process Metrics)• Predict project needsPredict project needs• Measure dynamic changesMeasure dynamic changes

Design Metrics (Product Metrics)Design Metrics (Product Metrics)• Measure the static state of project at a particular Measure the static state of project at a particular

point in time.point in time.

Page 4: Software Metrics

Object-Oriented Project Metrics Object-Oriented Project Metrics (Lorenz and Kidd)(Lorenz and Kidd)

Application SizeApplication Size Number of Scenario Scripts (NSS)Number of Scenario Scripts (NSS) Number of Key Classes (NKC)Number of Key Classes (NKC) Number of Subsystems (NOS)Number of Subsystems (NOS)

Staffing SizeStaffing Size Person-days per class (PDC)Person-days per class (PDC) Classes per developer (CPD)Classes per developer (CPD)

SchedulingScheduling Number of major iterations (NMI)Number of major iterations (NMI) Number of contracts completed (NCC)Number of contracts completed (NCC)

Page 5: Software Metrics

Chidamber & Kemerer (CK) MetricsChidamber & Kemerer (CK) Metrics

Weighted Methods per Class (WMC)Weighted Methods per Class (WMC)

Depth of Inheritance Tree (DIT)Depth of Inheritance Tree (DIT)

Number of Children (NOC)Number of Children (NOC)

Coupling Between Object Classes(CBO)Coupling Between Object Classes(CBO)

Response For a Class (RFC)Response For a Class (RFC)

Lack of Cohesion in Methods (LCOM)Lack of Cohesion in Methods (LCOM)

Page 6: Software Metrics

Weighted Methods Per Class (WMC)Weighted Methods Per Class (WMC)

Consider a Class Consider a Class C1 , with methods , with methods M1, …, , …, Mn that are defined in the class. Let that are defined in the class. Let c1, …, , …, cn be the complexity of the methods. Then: be the complexity of the methods. Then:

WMC = WMC =

If all method complexities are considered to If all method complexities are considered to be unity, then be unity, then

WMC = WMC = nn

n

iic

1

Page 7: Software Metrics

WMC ExampleWMC ExampleClass fooClass foo { {

int local_var;int local_var;int *pInt;int *pInt;

public:public:foo(){local var = 1;foo(){local var = 1; pInt = new int;}pInt = new int;}int f1(){return local_var;}int f1(){return local_var;}int f2(){return int f2(){return +++local_var+local_var;};}int f3(){return 1/f1();}int f3(){return 1/f1();}

}}

Assume all methods Assume all methods with the same with the same complexity: complexity:

WMC(foo) = 4WMC(foo) = 4

Page 8: Software Metrics

Depth of Inheritance Tree (DIT)Depth of Inheritance Tree (DIT)

Depth of inheritance of the class is the DIT Depth of inheritance of the class is the DIT metric for the class. metric for the class.

DIT = DIT = depth of the class in depth of the class in

the inheritance treethe inheritance tree

If multiple inheritance is allowed, If multiple inheritance is allowed,

DIT = DIT = the maximum length the maximum length

from the node to the root of the treefrom the node to the root of the tree

Page 9: Software Metrics

DIT ExampleDIT Example

DIT(A) = DIT (B) = 2DIT(A) = DIT (B) = 2

Page 10: Software Metrics

Number of Children (NOC)Number of Children (NOC)

NOC = NOC = number of immediate subclasses number of immediate subclasses subordinated to a class subordinated to a class

in the class hierarchyin the class hierarchy

Page 11: Software Metrics

NOC ExampleNOC Example

NOC(C) = 2NOC(C) = 2

Page 12: Software Metrics

Coupling Between Objects (CBO)Coupling Between Objects (CBO)

A count of the number of other classes to A count of the number of other classes to which it is coupled.which it is coupled. An object is coupled to another object if one of An object is coupled to another object if one of

them acts on the other.them acts on the other. Two classes are coupled when methods Two classes are coupled when methods

declared in one class use methods or instance declared in one class use methods or instance variables defined by the other class.variables defined by the other class.

Page 13: Software Metrics

CBO ExampleCBO Example

Class A {Class A {

::

M1(){M1(){

::

B.M1();B.M1();

C.M2();C.M2();

: }: }

}}

CBO (A) = 2CBO (A) = 2

Class B {Class B { ::M1(){M1(){

: }: } }}

Class C {Class C { ::M2(){M2(){

: }: }}}

Page 14: Software Metrics

Response for a Class (RFC)Response for a Class (RFC)

RFC = | RS | where RFC = | RS | where RS RS is the is the

response set for the classresponse set for the class

RS = {RS = {MM} } all iall i { {RRii} where} where

{{RRii} = set of methods called by method I and} = set of methods called by method I and

{{MM} = set of all methods in the class} = set of all methods in the class

Page 15: Software Metrics

RFC ExampleRFC Example

Class C1{M1(){…};M2 (){…};M3(){… C2.M1()};}

Class C2{M1(){…};}

RFC = 3 + 1 = 4

Page 16: Software Metrics

Lack of Cohesion in Methods (LCOM)Lack of Cohesion in Methods (LCOM)

• Consider a Class Consider a Class C1 , with , with nn methods methods M1, , …, …, Mn. Let . Let {Ij}= set of instance variables used by method Mi. There are There are n such sets such sets {{I1}, …, {}, …, {In}. Let P = {(}. Let P = {(Ii, , Ij)| )| Ii Ij = = } } and Q = {(and Q = {(Ii, , Ij)| )| Ii Ij }. If all }. If all n sets sets {{I1}, …, {}, …, {In} are } are then let P = then let P = ..

LCOM = | P | - | Q | , if | P | > | Q | LCOM = | P | - | Q | , if | P | > | Q | = 0 , otherwise= 0 , otherwise

Page 17: Software Metrics

LCOM ExampleLCOM Example

• Consider a Class Consider a Class C with 3 methods with 3 methods M1, , M1

and and M3. Let . Let {I1}= {a, b, c, d, e}, {I2}= {a, b, c} and {I3}= {x, y, z}.

• {I1} {I2} is nonempty, but {I1} {I3} and {I2} {I3} are null sets.

LCOM = | P | - | Q | | P | - | Q | = 2 – 1 = 1

Page 18: Software Metrics

New MetricsNew Metrics

Inheritance Coupling (IC)Inheritance Coupling (IC)

Coupling Between Methods (CBM)Coupling Between Methods (CBM)

Number of Object/Memory Allocation Number of Object/Memory Allocation (NOMA)(NOMA)

Average Method Complexity (AMC)Average Method Complexity (AMC)

Page 19: Software Metrics

Inheritance Coupling (IC)Inheritance Coupling (IC)

One of its inherited methods One of its inherited methods uses a variable uses a variable (or data (or data member) that is member) that is defined in a new/redefined methoddefined in a new/redefined method. .

One of its inherited methods One of its inherited methods calls a redefined methodcalls a redefined method and and uses the return valueuses the return value of the redefined method. of the redefined method.

One of its inherited methods is One of its inherited methods is called by a redefined called by a redefined methodmethod and and uses a parameteruses a parameter that is defined in the that is defined in the redefined method. redefined method.

One of its inherited methods uses a variable X, and One of its inherited methods uses a variable X, and the value of X depends on the value of a variable Y the value of X depends on the value of a variable Y which is defined in a new/redefined method.which is defined in a new/redefined method.

The number of The number of parent classesparent classes to which a given to which a given class is coupled.class is coupled.

Page 20: Software Metrics

New Metrics ExampleNew Metrics Example

Class fooClass foo { {

int local_var;int local_var;

int *pInt;int *pInt;

public:public:

foo(){local var = 1;foo(){local var = 1;

L2:L2: pInt = new int;} pInt = new int;}

int f1(){return local_var;}int f1(){return local_var;}

int f2(){return int f2(){return +++local_var+local_var;};}

int f3(){return 1/f1();}int f3(){return 1/f1();}

}}

Class foo_c1Class foo_c1 :: Public foo{ :: Public foo{

int f1(){return int f1(){return --local_var--local_var;};}

int f4(){return local_var++;}int f4(){return local_var++;}

}}

Class foo_c2Class foo_c2 :: Public foo{ :: Public foo{

int f2(){return 0;}int f2(){return 0;}

}}

Metrics Value: foo foo_c1 foo_c2 IC 0 1 0 CBM 0 3 0 NOMA 1 0 0 AMC 1.25 1 1

Page 21: Software Metrics

Coupling Between Methods (CBM)Coupling Between Methods (CBM)

Inherited method uses a Inherited method uses a variablevariable (or data member) (or data member) that is defined in a new/redefined method. that is defined in a new/redefined method.

Inherited method Inherited method calls a redefined methodcalls a redefined method and and uses the return valueuses the return value of the redefined method. of the redefined method.

Inherited method is Inherited method is called by a redefined methodcalled by a redefined method and and uses a parameteruses a parameter that is defined in the that is defined in the redefined method. redefined method.

Inherited method uses a variable X, and the value Inherited method uses a variable X, and the value of X depends on the value of a variable Y which is of X depends on the value of a variable Y which is defined in a new/redefined method.defined in a new/redefined method.

The total number of The total number of new/re-defined methodsnew/re-defined methods to to which all the which all the inherited methodsinherited methods are coupled. are coupled.

Page 22: Software Metrics

New Metrics ExampleNew Metrics Example

Class fooClass foo { {

int local_var;int local_var;

int *pInt;int *pInt;

public:public:

foo(){local var = 1;foo(){local var = 1;

L2:L2: pInt = new int;} pInt = new int;}

int f1(){return local_var;}int f1(){return local_var;}

int f2(){return int f2(){return +++local_var+local_var;};}

int f3(){return 1/int f3(){return 1/f1()f1();};}

}}

Class foo_c1Class foo_c1 :: Public foo{ :: Public foo{

int f1(){return int f1(){return --local_var--local_var;};}

int f4(){return int f4(){return local_var+local_var+++;};}

}}

Class foo_c2Class foo_c2 :: Public foo{ :: Public foo{

int f2(){return 0;}int f2(){return 0;}

}} Metrics Value: foo foo_c1 foo_c2 IC 0 1 0 CBM 0 3 0 NOMA 1 0 0 AMC 1.25 1 1

Page 23: Software Metrics

New MetricsNew Metrics

Number of Object/Memory Allocation Number of Object/Memory Allocation (NOMA)(NOMA) The total number of statements that allocate The total number of statements that allocate

new objects or memories in a class.new objects or memories in a class.

Average Method Complexity (AMC)Average Method Complexity (AMC) The average method size of a class.The average method size of a class.

Inheritance Coupling (IC)Inheritance Coupling (IC)Coupling Between Methods (CBM)Coupling Between Methods (CBM)

Page 24: Software Metrics

New Metrics ExampleNew Metrics Example

Class fooClass foo { {

int local_var;int local_var;

int *pInt;int *pInt;

public:public:

foo(){local var = 1;foo(){local var = 1;

L2:L2: pInt = pInt = new intnew int;};}

int f1(){return local_var;}int f1(){return local_var;}

int f2(){return +int f2(){return ++local_var;}+local_var;}

int f3(){return 1/f1();}int f3(){return 1/f1();}

}}

Class foo_c1Class foo_c1 :: Public foo{ :: Public foo{

int f1(){return --local_var;}int f1(){return --local_var;}

int f4(){return local_var++;}int f4(){return local_var++;}

}}

Class foo_c2Class foo_c2 :: Public foo{ :: Public foo{

int f2(){return 0;}int f2(){return 0;}

}}

Metrics Value: foo foo_c1 foo_c2 IC 0 1 0 CBM 0 3 0 NOMA 1 0 0 AMC 1.25 1 1

Page 25: Software Metrics

New MetricsNew Metrics

Number of Object/Memory Allocation Number of Object/Memory Allocation (NOMA)(NOMA) The total number of statements that allocate The total number of statements that allocate

new objects or memories in a class.new objects or memories in a class.

Average Method Complexity (AMC)Average Method Complexity (AMC) The average method size of a class.The average method size of a class.

Inheritance Coupling (IC)Inheritance Coupling (IC)Coupling Between Methods (CBM)Coupling Between Methods (CBM)

Page 26: Software Metrics

New Metrics ExampleNew Metrics Example

Class fooClass foo { {

int local_var;int local_var;

int *pInt;int *pInt;

public:public:

foo(){local var = 1;foo(){local var = 1;

L2:L2: pInt = new int;} pInt = new int;}

int f1(){return local_var;}int f1(){return local_var;}

int f2(){return +int f2(){return ++local_var;}+local_var;}

int f3(){return 1/f1();}int f3(){return 1/f1();}

}}

Class foo_c1Class foo_c1 :: Public foo{ :: Public foo{

int f1(){return --local_var;}int f1(){return --local_var;}

int f4(){return local_var++;}int f4(){return local_var++;}

}}

Class foo_c2Class foo_c2 :: Public foo{ :: Public foo{

int f2(){return 0;}int f2(){return 0;}

}}

Metrics Value: foo foo_c1 foo_c2 IC 0 1 0 CBM 0 3 0 NOMA 1 0 0 AMC 1.25 1 1