You are on page 1of 20

CS5228

Principles of Software Design and


g
g
Software Engineering

D i Metrics
Design
M ti

Architectural Analysis/Design Concerns


ArchitecturalAnalysis/DesignConcerns
Involvessystemlevel,largescaleandbroad
p
problemswhoseresolutionusuallyinvolveslarge
y
g
scaleorfundamentaldesigndecisions
Involvesconsideringinterdependenciesand
Involves considering interdependencies and
tradeoffs.
Generationandevaluationofalternative
solutions.

MeasuringDesignQuality
g
g
y
Why?
OnespecificationmanyDesigns!
One specification many Designs!

Subjective/Objective
Researchersdevelopingkeymetrics
h d l i k
i
Example
p
MetricforCoupling
SystemComplexity
System Complexity
Complexity=StructuralComplexity
+ Data Complexity
+DataComplexity

Measuring Design Quality (cont )


MeasuringDesignQuality(cont.)
ComparisonTables
Att ib t
Attribute

P i it ( t)
Priority(wt)

Reuse
Extendibility
Complexity

D i 1
Design1

D i 2
Design2

D i 3
Design3

Design Review Qs
DesignReviewQs
1.
2.
3
3.
4.
5.
6.
7.

Isthisdesignasolutiontotheproblem?
g
p
Isthedesignmodular,wellstructured?
I h d i
Isthedesignunderstandable
d
d bl
IsitPortable?
Isitreusable?
Isiteasytomodifyandextend?
Does it support ease of testing ?
Doesitsupporteaseoftesting?

Design Review Qs
DesignReviewQs
8. Doesthedesignmaximizeperformancewhere
appropriate?
9. Doesthedesignreusepatterns/code?
10.Arethealgorithmsappropriatecantheybe
p
improved?
11.Isthedesignwelldocumented?
12 Does the design cross reference the components
12.Doesthedesigncrossreferencethecomponents
anddatawiththerequirements?
13 D
13.Doesthedesignusetechniquesforfault
th d i
t h i
f f lt
tolerance?

Design Metrics
DesignMetrics
Design Metrics are useful in measuring the
complexity and goodness
goodness of a design
design.
A large number metrics have been proposed for
OO designs
Some of these have been validated
experimentally, others are mere proposals or
have received little or no validation
validation.
7

ExampleDesignMetrics
p
g
[Chidamber &Kemerer]

1. DesignComplexity
WeightedMethodsPerClass
W i ht d M th d P Cl

Sumofmethodcomplexities

2. DepthofInheritance
Maximum
MaximumLengthofthepathinthehierarchy
Length of the path in the hierarchy
fromtheclasstotherootoftheinheritancetree

3 NumberofChildren
3.
Number of Children
Numberofimmediatesubclasses

Example Design Metrics (Cont )


ExampleDesignMetrics(Cont.)
4. Coupling
Countofassociationswithotherclasses
C
t f
i ti
ith th l

5. LackofCohesioninMethods

Other Example Design Metrics


OtherExampleDesignMetrics
1. NumberofKeyClasses
2 NumberofSupportClasses
2.
Number of Support Classes
3. AveragenumberofKeyClassespersupport
class
l
4. Classsize
5. Numberofoperationsoverriddenbya
subclass (NOO).
subclass(NOO).
6. Numberofoperationsaddedbyasubclass

Other Example Design Metrics (cont )


OtherExampleDesignMetrics(cont.)
7. SpecializationIndex(Lorenz,Kidd)
SI NOO l l / t t l Cl M th d
SI=NOOxlevel/totalClassMethods

8. AveragenumberofParametersperoperation
9. Percentofpublic/protected
10 A
10.Amountofpublicaccesstodatamembers
t f bli
t d t
b
11.Fan_in
_ ((numberofclassescalling)
g)
12.Fan_out (numberofclassescalledby)

Weighted Methods Per Class (WMC)


Assumption:
Assumption:Theeffortindevelopingaclassis
The effort in developing a class is
determinedbythenumberofmethods.
Hence the overall complexity of a class can be
measured as a function of the complexity of its
methods.
methods
Let

c
i

denote the complexity of method

M
i

WMC

i 1

c
i

WMC metric has a reasonable correlation with


fault-proneness
p
of a class.

Depth of inheritance tree (DIT)


Depthofinheritancetree(DIT)
Inheritance increases coupling. Changing classes

becomes harder.
Depth
D h off IInheritance
h i
(DIT) off class
l
C is
i the
h length
l
h off the
h
shortest path from the root of the inheritance tree to C.
In the case of multiple inheritance DIT is the maximum

length of the path from the root to C.

DIT is significant in predicting error proneness of a


class.
class

Higher
Hi h DIT leads
l d to
t higher
hi h error-proneness.
13

Coupling between classes (CBC)


Couplingbetweenclasses(CBC)
Class C1 is coupled to class C2 if at least one method of C1
uses a method or an instance variable of C2.
CBC of C=total number of other classes to which C is coupled.
Most classes are self contained and have CBC=0.
Interface classes tend to have higher CBC values. CBC is
significant
i ifi t iin predicting
di ti ffault-proneness
lt
off classes.
l

Coupling Factor (CF)


CouplingFactor(CF)

is_client(x,y)=1iff arelationshipexists
b t
betweentheclientclassandtheserverclass.
th li t l
d th
l
0otherwise.
TCisthetotalnumberofrelationships
possible
CFis[0,1]with1meaninghighcoupling

Numberofchildren(NOC)
(
)
NOCisthenumberofimmediatesubclassesofC.
Higher values of NOC suggest reuse of the

definitions in the super-class in a larger number of


subclasses.

Higher NOC suggests the extent of influence of a

class on other elements of a design. Higher influence


demands higher quality from that class.
class

Larger
L
NOC value
l is
i associated
i t d with
ith lower
l
probability
b bilit

of detecting faults in that class.

Lackofcohesioninmethods(LCOM)
LetI1andI2denotesetsofinstancevariablesaccessedby
methodsM1andM2,respectively,inclassC.
h d
d
l
l
M1 and M2 are considered similar, or cohesive, if I1 and

I2 are not disjoint.

Let Q be the set of all cohesive method pairs.


p
Let P be the set of all non-cohesive method pairs.
LCOM=|P| - |Q| if |P| > |Q|, 0 otherwise.
A high value of LCOM suggests that a class is trying to

pp multiple
p abstractions. Perhaps
p the class needs
support
to be partitioned into smaller and more cohesive classes.

NumberofOperationsOverridden(NOO)
AlargenumberforNOOindicatespossible
p
problemswiththedesign
g
Poorabstractionininheritancehierarchy

NumberofOperationsAdded(NOA)
Thenumberofoperationsaddedbyasubclass
Asoperationsareaddeditisfartherawayfrom
As operations are added it is farther away from
superclass
AsdepthincreasesNOAshoulddecrease
A d th i
NOA h ld d

SpecializationIndex(SI)
SI=[NOO*L]/M
[
] / _total
Listhelevelinclasshierarchy
M_total
M total isthetotalnumberofmethods
is the total number of methods
Highervaluesindicateclassinhierarchythatdoes
notconformtotheabstraction
f
h b
i

MethodInheritanceFactor(MIF)

Mi(Ci)isthenumberofmethodsinheritedand
) is the number of methods inherited and
notoverriddeninCi
Ma(C
( i)isthenumberofmethodsthatcanbe
)i h
b
f
h d h
b
invokedwithCi
MIFis[0,1]
MIFnear1meanslittlespecialization
MIF near 1 means little specialization
MIFnear0meanslargechange

You might also like