Vous êtes sur la page 1sur 27

Object Oriented Metrics

McCall’s Triangle of Quality

M a in ta in a b ility P o r ta b ility
F le x ib ility R e u s a b ility
T e s ta b ility
IIn
n te r o p e r a b ilit y

P R O D U C T R E V IS IO N P R O D U C T T R A N S IT IO N

P R O D U C T O P E R A T IO N

C o rre c tn e s s U s a b ility E ff ic ie n c y
R e lia b ility I n te g r ity
Why Metrics?

 goal: good software design  low costs


 small testing effort
 low maintenance costs
 many reusable fragments

 definition of measurable criterions to


distinguish „good“ from „bad“ design
 use metrics to indicate source of „badness“

object oriented software metrics 3


Measures, Metrics and Indicators

 A measure provides a quantitative indication


of the extent, amount, dimension, capacity, or
size of some attribute of a product or process
 The IEEE glossary defines a metric as “a
quantitative measure of the degree to which a
system, component, or process possesses a
given attribute.”
 An indicator is a metric or combination of
metrics that provide insight into the software
process, a software project, or the product
itself
Metrics: general properties

 objective  consistent
 normative  reliable
 amenable to  useful
statistical analysis  valid
 comparable
 repeatable

object oriented software metrics 5


OO Metrics

 Measuring on class level


 Coupling
 Inheritance
 Cohesion
 Size
 Structural Complexity
 Measuring on package / higher level

object oriented software metrics 6


GQM Approach

1. List major Goals of


measurement
2. From each goal derive
the Questions that
must be answered to
determine if the goals
are met.
3. Decide what Metrics
must be collected in
order to answer the
questions.

object oriented software metrics 7


Metric Suites: Chidamber & Kemerer

 includes WMC, DIT, NOC, CBO, RFC, LCOM


 Advantages
 OO Design is considered
 NOC and RFC give some ideas as to budgeting
for testing a class
 Drawbacks
 no good size and effort estimation
 focus on design phase, not planning phase

object oriented software metrics 8


WMC (Weighted Methods per Class)
 Definition
 WMC is the sum of the complexity of the methods of a class.
 WMC = Number of Methods (NOM), when all method’s complexity
are considered UNITY.

 Viewpoints

 WMC is a predictor of how much TIME and EFFORT is required to


develop and to maintain the class.

 The larger NOM the greater the impact on children.

 Classes with large NOM are likely to be more application specific,


limiting the possibility of RE-USE and making the EFFORT
expended one-shot investment.

 Objective: Low 9
DIT (Depth of Inheritance Tree)
 Definition
The maximum length from the node to the root of the tree

 Viewpoints
The greater values of DIT :
 The greater the NOM it is likely to inherit, making more COMPLEX
to predict its behaviour
 The greater the potential RE-USE of inherited methods

 Small values of DIT in most of the system’s classes may be an


indicator that designers are forsaking RE-USABILITY for simplicity
of UNDERSTANDING.

 Objective: Trade-off

10
NOC (Number of Children)
 Definition
Number of immediate subclasses subordinated to a class in the class
hierarchy

 Viewpoints
The greater the NOC is:
 the greater is the RE-USE
 the greater is the probability of improper abstraction of the parent
class,
 the greater the requirements of method's TESTING in that class.

 Small values of NOC, may be an indicator of lack of communication


between different class designers.
 Objective: Trade-off
11
CBO (Coupling Between Objects)
 Definition
It is a count of the number of other classes to which it is coupled

 Viewpoints

Small values of CBO :


 Improve MODULARITY and promote ENCAPSULATION

 Indicates independence in the class, making easier its RE-USE

 Makes easier to MAINTAIN and to TEST a class.

 Objective: Low

12
RFC (Response for Class)

 Definition
It is the number of methods of the class plus the number of methods
called by any of those methods.

 Viewpoints
If a large numbers of methods are invoked from a class (RFC is
high):
 TESTING and MAINTANACE of the Class becomes more
COMPLEX.

 Objective: Low

13
LCOM (Lack of Cohesion of Methods)

 Definition
Measures the dissimilarity of methods in a class via instanced
variables.

 Viewpoints
Great values of LCOM:
 Increases COMPLEXITY

 Does not promotes ENCAPSULATION and implies classes


should probably be split into two or more subclasses
 Helps to identified low-quality design

 Objective: Low
14
CK Metrics: Guidelines
METRIC GOAL LEVEL COMPLEXITY RE-USABILITY ENCAPSULATION,
MODULARITY
(To develop, to test
and to maintain)

WMC Low ▼ ▼ ▲
DIT Trade-off ▼ ▼ ▼
▲ ▲ ▲
NOC Trade-off ▼ ▼ ▼
▲ ▲ ▲
CBO Low ▼ ▼ ▲
RFC Low ▼ ▼
LCOM Low ▼ ▼ ▲

15
Metrics for Object Oriented Design
Mood Suite
 By Fernando Brito e Abreu

 Method Hiding Factor (MHF)


 Attribute Hiding Factor (AHF)
 Method Inheritance Factor (MIF)
 Attribute Inheritance Factor (AIF)
 Polymorphism Factor (PF)
 Coupling Factor (CF)
Mood Suite
Encapsulation
 Method Hiding Factor (MHF):
 the ratio of the sum of the invisibilities of all methods
defined in all classes to the total number of methods
defined in the system under consideration.
The invisibility of a method is the percentage of the total
classes from which this method is not visible.

 Attribute Hiding Factor (AHF):


 the ratio of the sum of the invisibilities of all attributes
defined in all classes to the total number of attributes
defined in the system under consideration.
MHF

object oriented software metrics 18


AHF

object oriented software metrics 19


Mood Suite

Inheritance
 Method Inheritance Factor (MIF):
 the ratio of the sum of the inherited methods in all
classes of the system under consideration to the total
number of available methods ( locally defined plus
inherited) for all classes.

 Attribute Inheritance Factor (AIF):


 the ratio of the sum of inherited attributes in all classes
of the system under consideration to the total number of
available attributes ( locally defined plus inherited ) for
all classes.
MIF

object oriented software metrics 21


AIF

object oriented software metrics 22


Mood Suite
Polymorphism
– Polymorphism Factor (PF):
• the ratio of the actual number of possible different
polymorphic situation for class Ci to the maximum
number of possible distinct polymorphic situations for
class Ci.
Mood Suite
Message Passing
– Coupling Factor (CF):
• the ratio of the maximum possible number of couplings
in the system to the actual number of couplings (not
imputable to inheritance.)

– Note: a coupling can be a public or private attribute


or a public or private method argument
or local attribute
MOOD suite Summary
 Attribute Hiding Factor
(AHF)
 ideally 100 %
 Method Hiding Factor
(MHF)
 low: insufficient abstraction
 high: little functionality
 Attribute Inheritance Factor
(AIF)
 Method Inheritance Factor
(MIF)
 AIF and MIF should be
within acceptable range,
neither too high nor too low

object oriented software metrics 25


MOOD suite summary

 Polymorphism Factor (PF)


 should be within acceptable range
 Coupling Factor (CF)
 high CF values should be avoided

 MOOD conclusion
 not appropriate for projects relying mostly on forms and
standard modules

object oriented software metrics 26


Conclusion

 designed to measure overall quality of an OO


project
 we need unambiguous interpretation for software
metrics (individual result / result sets) to evaluate
design

object oriented software metrics 27

Vous aimerez peut-être aussi