Cs 5228 Lect 10 Design Metrics
description
Transcript of Cs 5228 Lect 10 Design Metrics
-
CS5228 Principles of Software Design and
Software Engineeringg g
D i M t iDesign Metrics
-
Architectural Analysis/Design ConcernsArchitecturalAnalysis/DesignConcerns
Involvessystemlevel,largescaleandbroadproblemswhoseresolutionusuallyinvolveslargep y gscaleorfundamentaldesigndecisions
Involves considering interdependencies and Involvesconsideringinterdependenciesandtradeoffs.
Generationandevaluationofalternativesolutions.solutions.
-
MeasuringDesignQualityg g y Why?
One specification many Designs!OnespecificationmanyDesigns! Subjective/Objective
h d l i k i Researchersdevelopingkeymetrics Examplep
MetricforCoupling System ComplexitySystemComplexityComplexity=StructuralComplexity
+ Data Complexity+DataComplexity
-
Measuring Design Quality (cont )MeasuringDesignQuality(cont.)
Att ib t P i it ( t) D i 1 D i 2 D i 3
ComparisonTables
Attribute Priority(wt) Design1 Design2 Design3
Reuse
ExtendibilityExtendibility
Complexity
-
Design Review QsDesignReviewQs1. Isthisdesignasolutiontotheproblem?g p
2. Isthedesignmodular,wellstructured?
3 I h d i d d bl3. Isthedesignunderstandable
4. IsitPortable?
5. Isitreusable?
6. Isiteasytomodifyandextend?
7. Does it support ease of testing ?7. Doesitsupporteaseoftesting?
-
Design Review QsDesignReviewQs8. Doesthedesignmaximizeperformancewhere
appropriate?9. Doesthedesignreusepatterns/code?10.Arethealgorithmsappropriatecantheybe
improved?p11.Isthedesignwelldocumented?12 Does the design cross reference the components12.Doesthedesigncrossreferencethecomponents
anddatawiththerequirements?13 D th d i t h i f f lt13.Doesthedesignusetechniquesforfault
tolerance?
-
Design MetricsDesignMetrics
Design Metrics are useful in measuring the complexity and goodness of a designcomplexity and goodness of a design.
A large number metrics have been proposed for OO designs
Some of these have been validated Some of these have been validated experimentally, others are mere proposals or have received little or no validation
7
have received little or no validation.
-
ExampleDesignMetricsp g[Chidamber &Kemerer]
1. DesignComplexityW i ht d M th d P Cl WeightedMethodsPerClass
Sumofmethodcomplexities
2. DepthofInheritance Maximum Length of the path in the hierarchyMaximumLengthofthepathinthehierarchy
fromtheclasstotherootoftheinheritancetree
3 Number of Children3. NumberofChildren Numberofimmediatesubclasses
-
Example Design Metrics (Cont )ExampleDesignMetrics(Cont.)
4. CouplingC t f i ti ith th l Countofassociationswithotherclasses
5. LackofCohesioninMethods
-
Other Example Design MetricsOtherExampleDesignMetrics
1. NumberofKeyClasses2 Number of Support Classes2. NumberofSupportClasses3. AveragenumberofKeyClassespersupport
lclass4. Classsize5. 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 dSI=NOOxlevel/totalClassMethods
8. AveragenumberofParametersperoperation
9. Percentofpublic/protected
10 A t f bli t d t b10.Amountofpublicaccesstodatamembers
11.Fan_in (numberofclassescalling)_ ( g)
12.Fan_out (numberofclassescalledby)
-
Weighted Methods Per Class (WMC)Weighted Methods Per Class (WMC) Assumption: The effort in developing a class isAssumption:Theeffortindevelopingaclassisdeterminedbythenumberofmethods.
Hence the overall complexity of a class can beHence the overall complexity of a class can be measured as a function of the complexity of its methodsmethods.
n cWMCicLet denote the complexity of method iM 1i i
cWMCi i
WMC metric has a reasonable correlation with fault-proneness of a class.p
-
Depth of inheritance tree (DIT)Depthofinheritancetree(DIT)
Inheritance increases coupling. Changing classes becomes harder.D h f I h i (DIT) f l C i h l h f h Depth of Inheritance (DIT) of class C is the length of the 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 classclass.
Hi h DIT l d t hi h13
Higher DIT leads to higher error-proneness.
-
Coupling between classes (CBC)Couplingbetweenclasses(CBC)
Class C1 is coupled to class C2 if at least one method of C1 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
i ifi t i di ti f lt f lsignificant in predicting fault-proneness of classes.
-
Coupling Factor (CF)CouplingFactor(CF)
is_client(x,y)=1iff arelationshipexistsb t th li t l d th lbetweentheclientclassandtheserverclass.0otherwise.
TCisthetotalnumberofrelationshipspossiblepossible
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 Higher NOC suggests the extent of influence of a class on other elements of a design. Higher influence demands higher quality from that classdemands higher quality from that class.
L NOC l i i t d ith l b bilit Larger NOC value is associated with lower probability of detecting faults in that class.
-
Lackofcohesioninmethods(LCOM)
LetI1andI2denotesetsofinstancevariablesaccessedbyh d d l lmethodsM1andM2,respectively,inclassC.
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.Q 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 support multiple abstractions. Perhaps the class needs pp p pto be partitioned into smaller and more cohesive classes.
-
NumberofOperationsOverridden(NOO) AlargenumberforNOOindicatespossibleproblemswiththedesignp g
Poorabstractionininheritancehierarchy
NumberofOperationsAdded(NOA) Thenumberofoperationsaddedbyasubclass As operations are added it is farther away from Asoperationsareaddeditisfartherawayfromsuperclass
A d th i NOA h ld d AsdepthincreasesNOAshoulddecrease
-
SpecializationIndex(SI) SI=[NOO*L]/M total[ ] / _ ListhelevelinclasshierarchyM total is the total number of methods M_total isthetotalnumberofmethods
Highervaluesindicateclassinhierarchythatdoesf h b inotconformtotheabstraction
-
MethodInheritanceFactor(MIF)
Mi(Ci) is the number of methods inherited andMi(Ci)isthenumberofmethodsinheritedandnotoverriddeninCi
( ) i h b f h d h b Ma(Ci)isthenumberofmethodsthatcanbeinvokedwithCi
MIFis[0,1] MIF near 1 means little specializationMIFnear1meanslittlespecializationMIFnear0meanslargechange