object-oriented metrics alex evans jonathan jakse cole fleming matt keran michael ababio

34
Object-Oriented Metrics Alex Evans Jonatha n Jakse Cole Fleming Matt Keran Michael Ababio

Upload: samuel-lamb

Post on 28-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Object-Oriented Metrics

Alex Evans

Jonathan Jakse

Cole Fleming

Matt Keran

Michael Ababio

What is OOM?

Measurements

Manage Predict Improve

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 Factor (CF)

Low coupling

Improves modular design

Encourages reuse of

components

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

Lack of Cohesion (LOCOM)

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

Hide attributes Large AHF Prevent

access

Attribute Hiding Factor (AHF)

Hide methods

Large MHF

Prevent Access

Method Hiding Factor (MHF)

Encapsulation Example

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

Low DIT

Less complex

Less reuse

Number of Children (NOC)

•Number of direct subclasses for each class

NOC

Low NOC

Reduced testing

Decrease complexity

Less risk of faults

Less reuse

DIT and NOC Example

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

Most of the classes are subclasses:

• Evenly Distributed

DIT Results Analysis

Most of the classes have no

children:

• Shallow

NOC Results Analysis

McCabe’s Cyclomatic Complexity

CC

Necessary to compute

WMC

Evaluate complexity of algorithm

Create Control

Flow Graph

Low CC

Decreased testing

Increased Understanding

Weighted Method Count (WMC)

Low WMC

Increased usability

Increased readability

Improved Understanding

• Edges: 8 • Nodes: 7

CC: 8 - 7 + 2 = 3

CC Example

Weighted Method Count Example

Redo classes with WMC 25 and 29• Decrease

complexity

Response For a Class

RFC

Number of methods invoked

by class

Methods executed in response to

message

Low RFC

Reduced complexity

Increased understanding

Improved readability

RFC for Class B

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

Class B Flow Chart

RFC Graphical Representation

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