object-oriented metrics alex evans jonathan jakse cole fleming matt keran michael ababio
TRANSCRIPT
LOCOM - Lack of Cohesion
WMC - Weighted Method Count
DIT - Depth of Inheritance Tree
NOC - Number of Children
RFC - Response for Class
CBO - Coupling Between Object Classes
Chidamber-Kemerer (CK) Suite
Metrics of OO Design (MOOD)
CF - Coupling Factor
AHF - Attribute Hiding Factor
MHF - Method Hiding Factor
MIF - Method Inheritance Factor
AIF - Attribute Inheritance Factor
PF - Polymorphism Factor
Coupling Example
Coupling Example
Coupling Example
• Number of non-inheritance couplings: 7• Max Number of Couplings: (9 * 8) / 2 = 36• CF = 7/36 = 0.1944
Correct class
subdivision
Decrease complexity
Reduced risk of errors
Increased reusability
Low LOCOM
Cohesion Example
Number of methods in class: 4%x = 2/4 = 0.5%y = ¼ = 0.25%z = ¼ = 0.25LOCOM = 1 - (0.5 + 0.25 + 0.25)/4 = 0.75
AHF ResultsAttributes Number classes not visible in %invisibility AHF
GUIfield1 6 85% 57%
GUIfield2 6 85%
GUIfield3 6 85%
P1field1 5 71%
P2field1 6 85%
P3field1 6 85%
P4field1 5 71%
DS1field1...4 3 43%
DS2field1...4 2 29%
MHF ResultsAttributes Number classes not visible in %invisibility MHF
GUImethod() 6 85% 77%
P1method1() 5 71%
P1method2() 6 85%
P1method3() 5 71%
P2method1() 4 57%
P2method2() 6 85%
P3method1() 5 71%
P4method1() 5 71%
P4method2()...4 6 85%
Depth of Inheritance Tree (DIT)
• Max length from class node to parent
• Classes should be distributed evenly
DIT
Some Results
Class Inheritance Depth Number of Children
Entity 0 3
Bullet 1 2
Player 1 0
Enemy 1 3
Zombie 2 0
Boss 2 1
NeonCat 3 0
McCabe’s Cyclomatic Complexity
CC
Necessary to compute
WMC
Evaluate complexity of algorithm
Create Control
Flow Graph
Weighted Method Count (WMC)
Low WMC
Increased usability
Increased readability
Improved Understanding
RFC for Class B
• Class B can call: FooA(), FooB(), FooB1(), FooC() (4)
• FooA() calls FooA1() (1)
• FooC() calls FooC1() (1)
• FooB1() and FooC1() call System.out.print () (1)
• RFC for Class B = 7
References
http://www.literateprogramming.com/ooapply.pdfhttp://agile.csc.ncsu.edu/SEMaterials/OOMetrics.htmhttp://www.arisa.se/compendium/node97.htmlhttp://www.ercim.eu/publication/Ercim_News/enw23/abreu.htmlhttp://www.cc.uah.es/drg/b/RodHarRama00.English.pdf