Top Banner
COHESION MEASUREMENTS By Abubakar Adam (April, 2004)
25

COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

Dec 22, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

COHESION MEASUREMENTS

By

Abubakar Adam(April, 2004)

Page 2: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

Outline

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

Page 3: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 4: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

Introduction (Cont..)

Subsystem2

Subsystem1

System

Page 5: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 6: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 7: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 8: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 9: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 10: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 11: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 12: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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) =

Page 13: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 14: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 15: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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 .

Page 16: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

Example of CBMC

m1

A1 A2 A3 A4

m2 m3 m4 m5

Page 17: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 18: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 19: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 20: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 21: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

The OCC and PCC

1,0

1,1

|)(|max

)( ,...,1

n

nn

miRwCOCC ni

1,0

1,1

|)(|max

)( ,...,1

n

nn

miRsCPCC ni

Page 22: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 23: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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.

Page 24: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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

Page 25: COHESION MEASUREMENTS By Abubakar Adam (April, 2004)

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