COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

25
COHESION MEASUREMENTS By Abubakar Adam (April, 2004)
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    223
  • download

    1

Transcript of COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

COHESION MEASUREMENTS

By

Abubakar Adam(April, 2004)

Outline

• Introduction• Cohesion metrics in the literature• Classification for cohesion metrics• New Metric

Introduction

• Cohesion determines the extent to which the individual components of a module are required to perform the same task

• While cohesion addresses intra-module connectedness, coupling addresses inter-module connectedness

Introduction (Cont..)

Subsystem2

Subsystem1

System

Introduction

• A cohesive module:– Has all its components tailored

towards one functionality– Does not rely on other modules– Is easy to maintain

• Cohesion should be maximized• Coupling should be minimized

Cohesion metrics

Let P be the pairs of methods without shared instance variables, and Q be the pairs of methods with shared instance variables. Then

LCOM2 =

otherwise

QPifQP

,0

|||||,|||

m

mAa

a

ij

1

)(1

1

# Metric

1 LCOM1

2 LCOM2

3 LCOM3

4 LCOM4

5 Co

6 LCOM5

7 LCC

8 TCC

9 RCI

10 CCM

11 ECCM

12 CBMC

13 OCC

14 PCC

LCOM1• LCOM1 is the number of pairs of methods with no

common attributes references • From the example given Below, LCOM1 = 2

m 1

A 1 A 2 A 3 A 4

m 2 m 3

C

LCOM2• Consider a class C with methods M1, M2,….., Mn. Let {Ii} = set of

instance variables used by method Mi. There are n such sets, i.e., {1i}, {I2},….., {In}. Let P = { (Ii, Ij ) | Ii Ij = } and Q = {(Ii, Ij ) | Ii Ij }. If all n sets {1i}, {I2},….., {In} are then let P = .

otherwise

QPifQP

,0

|||||,|||

LCOM2 =

P = 2 and Q = 1 thus LCOM2 = 1

m 1

A 1 A 2 A 3 A 4

m 2 m 3

C

LCOM3• Consider an undirected graph G where the vertices

are the methods of a class, and there is an edge between two vertices if the corresponding methods share at least one instance variable.

• LCOM3=|connected components of G|

G x

m 1

m 2

Cm 1

A 1 A 2 A 3 A 4

m 2 m 3

m 3

LCOM3 = 2

LCOM4• Like LCOM3, where graph G additionally has

an edge between vertices representing methods Mi and Mj, if Mi invokes Mj or vice versa.

m 1

m 2

C M e th o d in v o c a tio nm 1

A 1 A 2 A 3 A 4

m 2 m 3

G x

m 3

LCOM4 = 1

The Connectivity Metric

)2|).(|1|(|

)1|(|||2

cc

cc

VV

VECo(C) =

m 1

m 2

C M e th o d in v o c a tio nm 1

A 1 A 2 A 3 A 4

m 2 m 3

G x

m 3

From the example given above, we have Ec = 2 and Vc = 3. Hence, Co(C) = 0

The TCC and LCC Metrics

)(

)()(

CNP

CNDCCTCC

)(

)()()(

CNP

CNICCNDCCLCC

m 1

A 1 A 2 A 3 A 4

m 2 m 3

NDC(C) = 2, NIC(C) = 1 and NP(C) = 3,

Thus,

TCC = 2/3 and LCC = 1

2

)1(* NNNP(C) =

The LCOM5 Metric

m

mAa

a

jj

1

)(1

1

LCOM5 =

Cm 1

A 1

( ) = 1A 1( ) = 2A 1

( ) = 2A 1

A 2 A 3

m 2 M i

A j

m 3

From the example, we have: m = 3 and a = 3,

Thus,

LCOM5 = 2/3

The RCI Metric

|)(|

|)(|)(

CMax

CClCRCI

CI means cohesive interactions = the set of all DD- and DM-interactions present in the class C

Max(C) = the set of all possible DD- and DM-interactions that can be established in class C

m 1

A 1 A 2 A 3 A 4 A 5

m 2 m 3 m 4

CFrom the example we have, |CI(C)| = 8

|Max(C)| = 30

Hence,

RCI = 8/30 = 4/15

The CBMC Metrc

))((1

))(())(())(()(1

CGCBMCn

CGFCGFCGFCCBMC ir

n

ircrsrc

|)(|

|)(|))((

rn

rgrc GM

GMCGF

)(1

))((1

ir

n

irs GCBMC

nCGF

Mg = the set of glue methods

Mn = the set normal methods

Glue methods are the minimum number of methods without which the reference graph will be divided into sub-graphs.

It is one of the n children of Gr in the structure tree; CBMC denotes the cohesion of a component .

Example of CBMC

m1

A1 A2 A3 A4

m2 m3 m4 m5

A2

m1

A1 A2 A3 A4

m2 m3 m4 m5

A2 A3 A4

m3 m4 m5

A3 A4

m4 m5

A4

m5

m1

A1

A3

Example of CBMC (Cont..)

))((1

))(())(())(()(1

CGCBMCn

CGFCGFCGFCCBMC ir

n

ircrsrc

)()(2

1

5

1)( 21 GCBMCGCBMCCCBMC

)()(

2

1

3

11

10

11

10

1)( 2221 GCBMCGCBMCFFCCBMC SC

)()(

2

1

2

11

6

11

10

1)1

6

11

10

1)( 222221 GCBMCGCBMCFFCCBMC SC

8

1111

4

11

6

11

10

11

4

11

6

11

10

1)(

SC FFCCBMC

The CCM and ECCM Metrics

NORM(C) is the number of re-implemented methods and NOIM(C) is the number of inherited methods

)()(

)()(

CNCCCNMP

CNCCCCM

))(1()().(

)()( CtorPenaltyFac

CNCCCNMP

CNCCECCM

))(1()()( CtorPenaltyFacCCCMCECCM

)(

)()(

CNOIM

CNORMCtorPenaltyFac

CCM and ECCM Example

m1

A1 A2 A3 A4

m2 m3 m4 m5m 1 m 2

m 3

m 4m 5

NC(C) = 5, NMP(C) = 10 and NCC(C) = 1 hence CCM = 2/5

Note:ECCM = CCM because in this example no specification is given for the inherited methods

The OCC and PCC

1,0

1,1

|)(|max

)( ,...,1

n

nn

miRwCOCC ni

1,0

1,1

|)(|max

)( ,...,1

n

nn

miRsCPCC ni

General Examples# Metric Example1

m 1

A1 A2 A3 A4

m 2 m3 m 4 m5

Example2

m 1

A 1 A 2 A 3 A 4

m 2 m 3 m 4 m 5

Example3

m 1

A 1 A 2 A 3 A 4

m 2 m 3 m 4 m 5

Comment

1 LCOM1 6 6 0 2 LCOM2 6-3=3 6-4=2 0 3 LCOM3 2 1 1 4 LCOM4 2 1 1 5 Co N/A 0 1 6 LCOM5 13/16 = 0.81 ¾ = 0.75 7/4 = 1.75 7 LCC 0.6 1 1 8 TCC 0.3 0.4 1 9 RCI 7/30 = 0.23 8/30 = 0.27 13/30 = 0.43 10 CCM 3/20 = 0.15 4/10 = 0.4 1 11 ECCM N/A N/A N/A 12 CBMC 0 1/8 = 0.13 1 13 OCC ¾ = 0.75 4/4 = 1 4/4 = 1 14 PCC N/A N/A N/A

Classification for Cohesion Metrics• There are two types of classification criteria

– Factor– Characteristic

• Factors: these criteria identify the things that may affect the cohesiveness of a module.

• Characteristics: these criteria, as the name implies, describe the characteristics of the cohesion metric i.e the features of the metric.

Classification (Cont..)# Classification Criteria Description Source Remark 1 Underlying Approach Characteristic New 2 Cohesion Criteria Characteristic Briand 3 Coverage Completeness Characteristic New 4 Granularity Characteristic Briand 5 Soundness/Validity Characteristic New 6 Sensitivity Characteristic New 7 Ease of Impl. and use Characteristic New Similar to Briand’s objectivity criteria 8 Interpretation Characteristic New 9 Validation Characteristic Briand 10 Availability Characteristic New Similar to Braind’s usable criteria 11 Source Characteristic Briand 12 Connection Type Factor Briand 13 Special Methods Factor Briand Briand called this known problems 14 Inheritance Factor Briand 15 Indirect Connections Factor Briand 16 Connected Components Factor New In the reference graph

Evaluating The LCOM1 Metrics

# Attribute Approach 1 Underlying Approach The underlying approach for the proposed metric is the notion of degree

of similarity of methods initially proposed by Bunge 2 Cohesion Criteria Attribute sharing 3 Coverage Completeness 4 Granularity Measure cohesion at class level 5 Soundness/Validity The approach does not correctly capture the cohesion of a class though it

gives an idea of how cohesive a class is. The metric is ambiguous because two classes that are, intuitively, o f different cohesion will have the same value for the measure

6 Sensitivity 7 Ease of Impl. and use Can be implemented 8 Interpretation Can be automated but difficult to interpret the measure 9 Validation Not validated 10 Availability 11 Source 12 Connection Type 13 Special Methods No consideration was given for special methods in this approach 14 Inheritance N/A 15 Indirect Connection