4. oometrics

31
1 1 Object Oriented Metrics Object Oriented Metrics Ali Ali Kamandi Kamandi Sharif Sharif University of Technology University of Technology [email protected] [email protected] Spring 2007 Spring 2007

Upload: kbshailu

Post on 02-Aug-2015

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 4. OOMetrics

11

Object Oriented MetricsObject Oriented Metrics

Ali Ali KamandiKamandi

SharifSharif University of TechnologyUniversity of Technology

[email protected]@ce.sharif.edu

Spring 2007Spring 2007

Page 2: 4. OOMetrics

22

OO Metrics: IntroductionOO Metrics: Introduction�� Measurement and metrics are key components of any Measurement and metrics are key components of any

engineering discipline.engineering discipline.

�� The use of metrics for OO systems has progresses much The use of metrics for OO systems has progresses much

more slowly than the use of OO methods.more slowly than the use of OO methods.

�� As OO systems become more pervasive, it is essential As OO systems become more pervasive, it is essential

that software engineers have quantitative that software engineers have quantitative

measurements for assessing the quality of designs at measurements for assessing the quality of designs at

both the architectural and component levels.both the architectural and component levels.

�� The intent of OO( or nonThe intent of OO( or non--OO) metrics:OO) metrics:

•• To better understand the quality of the product.To better understand the quality of the product.

•• To assess the effectiveness of the process.To assess the effectiveness of the process.

•• To improve the quality of work performed at a To improve the quality of work performed at a

project level.project level.[Pressman 2001]

[Pressman]

Page 3: 4. OOMetrics

33

Principles of Metrics Principles of Metrics

�� Metrics must be Metrics must be

•• SimpleSimple

•• Easy to collect (automated)Easy to collect (automated)

•• Easy to interpretEasy to interpret

�� The selection of an extensive set of metrics will The selection of an extensive set of metrics will

depend on the project's characteristics and depend on the project's characteristics and

context context

[RUP]

Page 4: 4. OOMetrics

44

Metrics for the OO Design ModelMetrics for the OO Design Model

�� Whitmire[WHI97] describes several distinct and Whitmire[WHI97] describes several distinct and

measurable characteristics of an OO design:measurable characteristics of an OO design:

• Size (Population, Volume, Length, Functionality)(Population, Volume, Length, Functionality)

• Complexity

• Coupling/Cohesion

• Completeness

• Similarity (the degree to which two or more classes (the degree to which two or more classes

are similar)are similar)

• Volatility (the degree of change in an artifact (the degree of change in an artifact

because of defects or changing requirements )because of defects or changing requirements )

[Pressman]

Page 5: 4. OOMetrics

55

Software MetricsSoftware Metrics

�� Some Traditional MetricsSome Traditional Metrics

•• McCabe McCabe CyclomaticCyclomatic Complexity (CC)Complexity (CC)

•• Lines of Code (LOC)Lines of Code (LOC)

•• Comment Percentage (CP)Comment Percentage (CP)

�� Some ObjectSome Object--Oriented MetricsOriented Metrics

•• Weighted Methods Per Class (WMC)Weighted Methods Per Class (WMC)

•• Coupling Between Object Classes (CBO)Coupling Between Object Classes (CBO)

•• Response for a Class (RFC)Response for a Class (RFC)

•• Depth of Inheritance Tree (DIT)Depth of Inheritance Tree (DIT)

•• Lack of Cohesion in Methods (LOCM)Lack of Cohesion in Methods (LOCM)

Page 6: 4. OOMetrics

66

Researches on OO MetricsResearches on OO Metrics

�� ChidamberChidamber and and KemererKemerer: CK Metrics Suite, 1994: CK Metrics Suite, 1994

�� CK suite validated by CK suite validated by BasiliBasili in 1996 and again by in 1996 and again by

Tang in 1999Tang in 1999

�� Many other objectMany other object--oriented metrics are derived oriented metrics are derived

from the CK suite of objectfrom the CK suite of object--oriented metrics oriented metrics

�� Lorenz and Kidd 1994Lorenz and Kidd 1994

�� Harrison, Harrison, CounsellCounsell and and NithiNithi, MOOD Metric Suite, , MOOD Metric Suite,

19981998

�� WhitmireWhitmire: OO Design Measurements, 1997: OO Design Measurements, 1997

�� ……

Page 7: 4. OOMetrics

77

ClassClass--Oriented Metrics 1Oriented Metrics 1

�� ChidamberChidamber and and KemererKemerer 1994:1994:

�� WMC: weightedWMC: weighted methods per classmethods per class ((ΣΣ

complexity of methods) (low)complexity of methods) (low)

�� Amount of effort required to implement and Amount of effort required to implement and

test a classtest a class

�� The larger the number of methods, the more The larger the number of methods, the more

complex is the inheritance tree.complex is the inheritance tree.

�� Large number of methods: Application specific Large number of methods: Application specific

and limiting potential reuse and limiting potential reuse

[Pressman]

Page 8: 4. OOMetrics

88

ClassClass--Oriented Metrics 2Oriented Metrics 2

�� ChidamberChidamber and and KemererKemerer 1994:1994:

•• DIT: depth of the inheritance treeDIT: depth of the inheritance tree (Max length (Max length

node to root) (low)node to root) (low)

�� Lower level classes inherit many methods. Lower level classes inherit many methods.

�� Difficulties when attempting to predict the Difficulties when attempting to predict the

behavior of a class.behavior of a class.

�� Greater design complexity.Greater design complexity.

�� Positive: many methods may be reusedPositive: many methods may be reused

[Pressman]

Page 9: 4. OOMetrics

99

ClassClass--Oriented Metrics 3Oriented Metrics 3

�� ChidamberChidamber and and KemererKemerer 1994:1994:

•• NOC: number of childrenNOC: number of children ( subclasses that are ( subclasses that are

immediately subordinate to a class)immediately subordinate to a class)

�� High: reuse, the amount of testHigh: reuse, the amount of test

[Pressman]

Page 10: 4. OOMetrics

1010

ClassClass--Oriented Metrics 4Oriented Metrics 4

�� ChidamberChidamber and and KemererKemerer (Continue):(Continue):

•• CBO:CBO: coupling between object classescoupling between object classes (No. of (No. of

coll. in CRC) (low)coll. in CRC) (low)

�� High: reusability will decrease, complicated High: reusability will decrease, complicated

testing and modificationstesting and modifications

�� This is consistent with the general guideline to This is consistent with the general guideline to

reduce coupling.reduce coupling.

[Pressman]

Page 11: 4. OOMetrics

1111

ClassClass--Oriented Metrics 5Oriented Metrics 5

�� ChidamberChidamber and and KemererKemerer (Continue):(Continue):

•• RFC: responsibility for a classRFC: responsibility for a class (No. of methods in (No. of methods in

response set) (low)response set) (low)

�� High: Testing and overall design complexity will High: Testing and overall design complexity will

increase.increase.

•• LCOM: lack of cohesion in methodsLCOM: lack of cohesion in methods (No of (No of

methods that access one or more of the same methods that access one or more of the same

attributes) (low)attributes) (low)

�� High: Complexity of class design, class might be High: Complexity of class design, class might be

better designed by breaking it into two or more better designed by breaking it into two or more

separate classes.separate classes.

�� It is desirable to keep cohesion high; that is keep It is desirable to keep cohesion high; that is keep

LCOM low.LCOM low.

[Pressman]

Page 12: 4. OOMetrics

1212

ClassClass--Oriented Metrics 6Oriented Metrics 6

�� Lorenz and Kidd [LOR94]: Lorenz and Kidd [LOR94]:

•• SizeSize--oriented:oriented: Counts of attributes and operations.Counts of attributes and operations.

•• InheritanceInheritance--based:based: The manner in which operations are The manner in which operations are

reused through the class hierarchy.reused through the class hierarchy.

•• InternalsInternals: Look at cohesion and code: Look at cohesion and code--oriented issues.oriented issues.

•• Externals:Externals: Examine coupling and reuse.Examine coupling and reuse.

�� A Sampling of Metrics:A Sampling of Metrics:

•• CS:CS: class size (no. of operations) (no. of attributes) (low)class size (no. of operations) (no. of attributes) (low)

�� High: class has too much responsibility, reduce the High: class has too much responsibility, reduce the

reusability, complicate implementation and testingreusability, complicate implementation and testing

•• NOO:NOO: number of operations overridden by a subclass (low)number of operations overridden by a subclass (low)

•• NOA:NOA: number of operations added by a subclassnumber of operations added by a subclass

•• SI:SI: specialization index = NOO * level / total no of methodsspecialization index = NOO * level / total no of methods

[Pressman]

Page 13: 4. OOMetrics

1313

ClassClass--Oriented MetricsOriented Metrics

�� Method inheritance factor: inherited methods / total methodsMethod inheritance factor: inherited methods / total methods

�� Coupling factor: formulaCoupling factor: formula

�� Polymorphism factor: formulaPolymorphism factor: formula

The MOOD Metrics Suite: Harrison, The MOOD Metrics Suite: Harrison, CounsellCounsell and and NithiNithi, 1998, 1998

[Pressman]

Page 14: 4. OOMetrics

1414

OperationOperation--Oriented MetricsOriented Metrics

�� average operation sizeaverage operation size

�� operation complexityoperation complexity

�� average number of parameters per average number of parameters per

operationoperation

Lorenz and Kidd [LOR94]:Lorenz and Kidd [LOR94]:

[Pressman]

Page 15: 4. OOMetrics

1515

Testability MetricsTestability Metrics

�� encapsulation relatedencapsulation related

•• lack of cohesion in methodslack of cohesion in methods

•• percent public and protectedpercent public and protected

•• public access to data memberspublic access to data members

�� inheritance relatedinheritance related

•• number of root classesnumber of root classes

•• fan in: multiple inheritancefan in: multiple inheritance

•• number of children and depth of inheritance treenumber of children and depth of inheritance tree

Proposed by Binder [BIN94]:Proposed by Binder [BIN94]:

[Pressman]

Page 16: 4. OOMetrics

1616

OO Project MetricsOO Project Metrics

�� number of scenario scriptsnumber of scenario scripts

�� number of key classesnumber of key classes

�� number of subsystemsnumber of subsystems

Proposed by Lorenz and Kidd [LOR94]:Proposed by Lorenz and Kidd [LOR94]:

[Pressman]

Page 17: 4. OOMetrics

1717

Req. and Use Case Model Metrics [RUP]Req. and Use Case Model Metrics [RUP]

Defects - number of defects, by severity

Reported complexity (0-5, by analogy with COCOMO [BOE81])

Quality

Number of defects and change requestsVolatility

Staff-time units (with production, change and repair separated) Effort

Number of requirements

Number of Use Cases

Number of scenarios, total and per use case

Number of actors

Length of Use Case (pages of event flow, for example)

Size

MetricsCharacteristic

Page 18: 4. OOMetrics

1818

Requirements and Use Case Model Metrics (2)Requirements and Use Case Model Metrics (2)

Analysis

• Scenarios realized in analysis model/total scenarios Design

• Scenarios realized in design model/total scenarios Implementation

• Scenarios realized in implementation model/total

scenarios Test

• Scenarios realized in test model (test cases)/total

scenarios Requirements-to-UC Traceability = Traceable to Use-Case

Model/Total number of requirements

Traceability

Use Cases completed (reviewed and under configuration

management with no defects outstanding)/use cases identified (or

estimated number of use cases)

Completeness

MetricsCharacteristic

Page 19: 4. OOMetrics

1919

OO Design Model Metrics [RUP]OO Design Model Metrics [RUP]

Number of defects and change requests (open, closed) Volatility

Staff-time units (with production, change and repair

separated)

Effort

Number of classes

Number of subsystems

Number of subsystems of subsystems …

Number of packages

Methods per class, internal, external

Attributes per class, internal, external

Depth of inheritance tree

Number of children

Size

MetricsCharacteristic

Page 20: 4. OOMetrics

2020

OO Design Model Metrics (2) [RUP]OO Design Model Metrics (2) [RUP]

Number of classes in Implementation Model/number of classesTraceability

Number of classes completed/number of classes estimated (identified) Completeness

Number of defects, by severity (open, closed) Defects

Number of children Cohesion

Number of children

Coupling between objects (class fan-out)

Coupling

Response For a Class (RFC): this may be

difficult to calculate because a complete set

of interaction diagrams is needed.

ComplexityQuality

MetricsCharacteristic

Page 21: 4. OOMetrics

2121

OO Implementation Metrics (1) [RUP]OO Implementation Metrics (1) [RUP]

Number of defects and change requests (open, closed)

Breakage for each corrective or perfective change, estimated (prior

to fix) and actual (upon closure)

Volatility

Staff-time units (with production, change and repair separated) Effort

Number of classes

Number of components

Number of implementation subsystems

Number of subsystems of subsystems …

Number of packages

Methods per class, internal, external

Attributes per class, internal, external

Size of methods, Size of attributes

Depth of inheritance tree

Number of children

Estimated size at completion

Size

MetricsCharacteristic

Page 22: 4. OOMetrics

2222

OO Implementation Metrics (2) [RUP]OO Implementation Metrics (2) [RUP]

Number of classes unit tested/number of classes in design model

Number of classes integrated/number of classes in design model

Active integration and system test time (accumulated from test

process), that is, time with system operating (used for maturity

calculation)

Completeness

Number of defects, by severity, open, closed Defects

Number of children

Lack of cohesion in methods (LCOM)

Cohesion

Number of children

Coupling between objects (class fan-out)

Message passing coupling (MPC) [Li and

Henry 1993]

Coupling

Response For a Class (RFC)

Cyclomatic complexity of methods*

ComplexityQuality

MetricsCharacteristic

Page 23: 4. OOMetrics

2323

Test Metrics [RUP]Test Metrics [RUP]

Number of successful Test Cases in Test Evaluation

Summary/Number of test cases

Traceability

Number of test cases written/number of test cases estimated

Code coverage

Completeness

Defects — number of defects by severity, open, closed (these are

defects raised against the test model itself)

Quality

Number of defects and change requests (open, closed)Volatility

Staff-time units for production of test cases, and so on Effort

Number of Test Cases, Test Procedures, Test Scripts Size

MetricsCharacteristic

Page 24: 4. OOMetrics

2424

Change Management Metrics [RUP]Change Management Metrics [RUP]

Number of defects discovered/number of defects predictedCompleteness

Breakage (estimated, actual) for the implementation model

subset.

Volatility

Defect repair effort, change implementation effort in staff-

time units

Effort

Number of defects, change requests by severity and status,

also categorized as number of perfective changes, number

of adaptive changes and number of corrective changes.

Size

MetricsCharacteristic

Page 25: 4. OOMetrics

2525

Process MetricsProcess Metrics

�� DurationDuration

�� EffortEffort

�� Training timeTraining time

�� Inspection timeInspection time

�� Meeting timeMeeting time

�� Process ProblemProcess Problem

Page 26: 4. OOMetrics

2626

Project MetricsProject Metrics

�� Cost/Schedule Control Cost/Schedule Control

•• BCWS, Budgeted Cost for Work Scheduled BCWS, Budgeted Cost for Work Scheduled

•• BCWP, Budgeted Cost for Work Performed BCWP, Budgeted Cost for Work Performed

•• ACWP, Actual Cost of Work Performed ACWP, Actual Cost of Work Performed

�� ModularityModularity = average breakage (NCNB*) per perfective or = average breakage (NCNB*) per perfective or

corrective change on implementation model corrective change on implementation model

�� AdaptabilityAdaptability = average effort per perfective or corrective = average effort per perfective or corrective

change on implementation model change on implementation model

�� ……

�� * NCNB is non* NCNB is non--comment, noncomment, non--blank code size.blank code size.

Page 27: 4. OOMetrics

2727

Data Analysis: Example (1)Data Analysis: Example (1)

�� ProjectsProjects

-- Project A: 46 Java Classes (Commercial Software)Project A: 46 Java Classes (Commercial Software)

-- ObjectObject--Oriented ConstructsOriented Constructs

-- Project B: 1000 Java Classes (NASA Software)Project B: 1000 Java Classes (NASA Software)

-- Excellent ObjectExcellent Object--Oriented ConstructsOriented Constructs

-- Project C: 1617 C++ Classes (NASA Software)Project C: 1617 C++ Classes (NASA Software)

-- Good ObjectGood Object--Oriented ConstructsOriented Constructs

Page 28: 4. OOMetrics

2828

Data Analysis: Example (2)Data Analysis: Example (2)

�� Correlation of Metrics over ProjectsCorrelation of Metrics over Projects

�� Metric 1 x Metric 2 = correlation between metric Metric 1 x Metric 2 = correlation between metric

1 and metric 2. 1 and metric 2.

0.830.830.260.260.350.35Project Project

CC

0.750.750.110.110.280.28Project Project

BB

0.470.470.430.430.830.83Project Project

AA

RFCxWMCRFCxWMCCBOxWMCCBOxWMCCBOxRFCCBOxRFC

Page 29: 4. OOMetrics

2929

Data Analysis: Example (3)Data Analysis: Example (3)

�� Regression ModelRegression Model

�� -- RFC = RFC = ββ11WMC + WMC + ββ22CBO + ConstantCBO + Constant

0.700.70

996.0396.0390.1480.1480.7920.792RFCRFC

CC

0.600.60

8815.42715.4270.2000.2000.7320.732RFCRFC

BB

0.700.70

888.0368.0360.7770.7770.1310.131RFCRFC

AA

RR22ConstantsConstantsββCBOCBOββWMCWMC

Page 30: 4. OOMetrics

3030

ReferencesReferences

�� [PRE01] Pressman, R. S., Software Engineering, A Practitioners A[PRE01] Pressman, R. S., Software Engineering, A Practitioners Approach, pproach, 55thth Ed., McGrawEd., McGraw--Hill, 2001.Hill, 2001.

�� [ROY98] Walker Royce 1998. [ROY98] Walker Royce 1998. Software Project Management: A Unified Software Project Management: A Unified Framework.Framework. Addison Wesley Longman.Addison Wesley Longman.

�� [CHI94] [CHI94] ChidamberChidamber, S. R. and C. F. , S. R. and C. F. KemererKemerer, , ““A Metrics Suite for Object A Metrics Suite for Object Oriented DesignOriented Design””, IEEE Trans. Software Engineering, vol. SE, IEEE Trans. Software Engineering, vol. SE--20, no. 6, 20, no. 6, June 1994, pp. 476June 1994, pp. 476--493.493.

�� [HAR98] Harrison, R. S.J. [HAR98] Harrison, R. S.J. CounsellCounsell, and R. V. , and R. V. NithiNithi, , ““An Evaluation of the An Evaluation of the MOOD set of ObjectMOOD set of Object--Oriented Software Metrics,Oriented Software Metrics,”” IEEE Trans. Software IEEE Trans. Software Engineering, vol. SEEngineering, vol. SE--24, no. 6, June 1998, pp. 49124, no. 6, June 1998, pp. 491--496.496.

�� [LOR94] Lorenz, M. and J. Kidd, Object[LOR94] Lorenz, M. and J. Kidd, Object--Oriented Design Metrics, PrenticeOriented Design Metrics, Prentice--Hall, 1994.Hall, 1994.

�� [WHI97] [WHI97] WhitmireWhitmire, S., Object, S., Object--Oriented Design Measurement, Wiley, 1997.Oriented Design Measurement, Wiley, 1997.

�� [BIN94] Binder, R. V., [BIN94] Binder, R. V., ““ObjectObject--Oriented Software Testing,Oriented Software Testing,”” CACM, vol. 37, CACM, vol. 37, no. 9, no. 9, septemberseptember 1994, p. 29.1994, p. 29.

Page 31: 4. OOMetrics

3131

Questions?Questions?