SW Metrics
SW Metrics
>
=
otherwise 0
if
) (
Q P Q P
C LCOM
[BBM] 180 classes
Discriminative ability
is insufficient
What about get/set?
First solution: LCOMN
Defined similarly to LCOM but allows negative values
/ SET / W&I PAGE 36 27-4-2011
Q P C LCOMN = ) (
LCOM LCOMN
Still
/ SET / W&I PAGE 37 27-4-2011
Method * method tables
Light blue: Q, dark blue: P
Calculate the LCOMs
Does this correspond to your intuition?
Henderson-Sellers, Constantine and Graham 1996
m number of methods
v number of variables (attrs)
m(V
i
) - #methods that access V
i
/ SET / W&I PAGE 38 27-4-2011
m
m V m
v
v
i
i
|
.
|
\
|
=
1
) (
1
1
Cohesion is maximal: all methods access all variables
and
No cohesion: every method accesses a unique variable
and
Can LCOM exceed 1?
m V m
i
= ) (
0 = LCOM
1 ) ( =
i
V m
1 = LCOM
LCOM > 1?
/ SET / W&I PAGE 39 27-4-2011
If some variables are not accessed at all, then
and
Hence
LCOM is undefined for m = 1
LCOM 2
1
1
1
1 1
) (
1
1
+ =
|
.
|
\
|
=
m m
m
m
m V m
v
v
i
i
0 ) ( =
i
V m
Evolution of LCOM [Henderson-Sellers et al.]
Project 6 (commercial human resource system)
suggests stabilization, but no similar conclusion can
be made for other projects
/ SET / W&I PAGE 40 27-4-2011
Sato, Goldman,
Kon 2007
Shortcomings of LCOM [Henderson-Sellers ]
Due to [Fernndez, Pea 2006]
Method-variable diagrams: dark spot = access
LCOM( ) = LCOM( ) = LCOM( ) = 0.67
seems to be less cohesive than and !
/ SET / W&I PAGE 41 27-4-2011
Variables
M
et
ho
ds
Variables
M
et
ho
ds
Variables
M
et
ho
ds
Alternative [Hitz, Montazeri 1995]
LCOM as the number of strongly
connected components in the
following graph
Vertices: methods
Edge between a and b, if
a calls b
b calls a
a and b access the same variable
LCOM values
0, no methods
1, cohesive component
2 or more, lack of cohesion
/ SET / W&I PAGE 42 27-4-2011
Variables
M
et
ho
ds
Variables
M
et
ho
ds
Question: LCOM?
Experimental evaluation of LCOM variants
Cox, Etzkorn and
Hughes 2006
Correlation with expert assessment
Group 1 Group 2
Chidamber Kemerer -0.43 (p = 0.12) -0.57 (p = 0.08)
Henderson-Sellers -0.44 (p = 0.12) -0.46 (p = 0.18)
Hitz, Montazeri -0.47 (p = 0.06) -0.53 (p = 0.08)
/ SET / W&I PAGE 43 27-4-2011
Etzkorn, Gholston,
Fortune, Stein,
Utley, Farrington,
Cox
Correlation with expert assessment
Group 1 Group 2
Chidamber Kemerer -0.46 (rating 5/8) -0.73 (rating 1.5/8)
Henderson-Sellers -0.44 (rating 7/8) -0.45 (rating 7/8)
Hitz, Montazeri -0.51 (rating 2/8) -0.54 (rating 5/8)
LCC and TCC [Bieman, Kang 1994]
Recall: LCOM HM a and b access the same variable
What if a calls a, b calls b, and a and b access the
same variable?
Metrics
NDP number of pairs of methods directly
accessing the same variable
NIP number of pairs of methods directly or
indirectly accessing the same variable
NP number of pairs of methods: n(n-1)/2
Tight class cohesion TCC = NDP/NP
Loose class cohesion LCC = NIP/NP
NB: Constructors and destructors are excluded
/ SET / W&I PAGE 44 27-4-2011
Experimental evaluation of LCC/TCC
/ SET / W&I PAGE 46 27-4-2011
Etzkorn, Gholston,
Fortune, Stein, Utley,
Farrington, Cox
Correlation with expert assessment
Group 1 Group 2
Chidamber Kemerer -0.46 (rating 5/8) -0.73 (rating 1.5/8)
Henderson-Sellers -0.44 (rating 7/8) -0.45 (rating 7/8)
Hitz, Montazeri -0.51 (rating 2/8) -0.54 (rating 5/8)
TCC -0.22 (rating 8/8) -0.057 (rating 8/8)
LCC -0.54 (rating 1/8) -0.73 (rating 1.5/8)
Conclusions: Metrics so far
/ SET / W&I PAGE 47 27-4-2011
Level Matrics
Method LOC, McCabe, Henry Kafura
Class WMC, NOC, DIT, LCOM (and
variants), LCC/TCC
Packages ???
Next time:
Package-level metrics (Martin)
Metrics of change