Design Quality Assessment in Practice my two hats... Radu Marinescu radum@cs.upt.ro http://www.intooitus.com/ Associate Professor Co-Founder and Head since 2006 since 2003 Co-Founder (2008)
1 1 Assessment with metrics Assessment with metrics 2 3 Assessment with Assessment with pictures tools Software is complex. 29% Succeeded forward engineering 18% Failed 53% Challenged { { { { } } } } The Standish Group, 2004
When, due to constraints, I design quickly and dirty , forward engineering my project is loaded with technical debt . W.Cunningham, 1992 { { { { { { } { { actual development } ? } } } } } } } { You cannot control How can I control this... what you cannot measure . Tom de Marco
Metrics compress system traits into numbers . Let’s see some examples ... Examples of metrics ... LOC - number of lines of code CYCLO - cyclomatic complexity of a function NOF - number of functions FANOUT - outgoing coupling NOA - number of attributes DIT - depth of inheritance tree Lorenz, Kidd, 1994 TCC - tight class cohesion Chidamber, Kemerer, 1994
Trouble in paradise... Trouble 1: Thresholds
Metric Value LOC ? 35175 NOM 3618 NOC 384 CYCLO 5579 Are these numbers “ normal ” ? NOP 19 FANOUT 8590 We need means to compare . We need comparable metrics .
Overview Pyramid provides a metrics overview. Overview Pyramid provides a metrics overview. Marinescu, Lanza Marinescu, Lanza Inheritance ANDC ANDC 0.31 0.31 AHH AHH 0.12 0.12 NOP NOP 20.21 19 20.21 19 NOC NOC 9.42 384 9.42 384 NOM NOM NOM NOM 9.72 3618 418 9.72 3618 418 LOC CALLS LOC CALLS 0.15 35175 15128 0.56 0.15 35175 15128 0.56 CYCLO 5579 8590 FANOUT CYCLO 5579 8590 FANOUT Size Communication Size Overview Pyramid provides a metrics overview. Java C++ Marinescu, Lanza LOW AVG HIGH LOW AVG HIGH CYCLO/LOC 0.16 0.20 0.24 0.20 0.25 0.30 ANDC 0.31 LOC/NOM 7 10 13 5 10 16 + OSS projects AHH 0.12 NOP 20.21 19 0 NOM/NOC 4 7 10 4 9 15 0 0 NOC 9.42 384 + LOC . 4 0 NOM NOM 0 9.72 3618 418 ... 0 . 0 0.15 LOC 35175 15128 CALLS 0.56 0 0 CYCLO FANOUT 5579 8590 . 0 0 5
The Overview Pyramid provides a metrics The Overview Pyramid provides a metrics overview. overview. Marinescu, Lanza Marinescu, Lanza ANDC ANDC 0.31 0.31 AHH AHH 0.12 0.12 NOP NOP 20.21 19 20.21 19 NOC NOC 9.42 384 9.42 384 NOM NOM NOM NOM 9.72 3618 418 9.72 3618 418 LOC CALLS LOC CALLS 0.15 35175 15128 0.56 0.15 35175 15128 0.56 CYCLO 5579 8590 FANOUT CYCLO 5579 8590 FANOUT close to high close to average close to low The Overview Pyramid provides a metrics overview. Marinescu, Lanza Trouble 2: Granularity close to high close to average close to low
Metrics are aggregated in quality models ... ? Problem: we don’t reason in terms of metrics, but in terms of design principles McCall, 1977
Capture violations of design principles & best practices An example... in an automatic manner... Detection Strategies are metric-based queries to detect design flaws. God Classes tend to centralize the intelligence of the Marinescu system, to do everything and to use data from small data-classes. A.Riel, 1996 Rule 1 METRIC 1 > Threshold 1 AND Quality problem Rule 2 METRIC 2 < Threshold 2
God Classes tend God Classes to centralize the intelligence of the system, centralize the intelligence of the system, to do everything and do everything and to use data from small data-classes. use data from small data-classes. A God Class centralizes too much intelligence in God Classes the system. Marinescu, Lanza are complex, are not cohesive, Class uses directly more than a access external data. few attributes of other classes ATFD > FEW Compose metrics into queries using Functional complexity of the class is very high logical operators AND GodClass WMC ≥ VERY HIGH Class cohesion is low TCC < ONE THIRD
Marinescu, Lanza Marinescu, Lanza Shotgun Shotgun Surgery Surgery has uses is Feature Data Feature Data has (partial) Envy Class Envy Class uses is partially God God has Intensive Intensive Class Class Brain Brain has Coupling Coupling has Method Method Dispersed Brain Dispersed Brain has Significant Significant Coupling Class Coupling Class Duplication Duplication has is is has Refused Refused Tradition is Tradition Parent Parent Breaker Breaker Bequest Bequest has (subclass) Futile Futile Hierarchy Hierarchy Identity Collaboration Classification Identity Collaboration Classification Disharmonies Disharmonies Disharmonies Disharmonies Disharmonies Disharmonies Measure quality deficit based on design problems Measure quality deficit based on design problems Quality 2 1 2 Hierarchies Shotgun Surgery 2 Understandab andability Reusability has Changeability Reusability 2 is uses 2 Cohesion 2 has (partial) Feature Data Envy uses Class 1 1 2 2 is partially 2 2 1 God has Intensive Specifi Class Brain has Coupling has 1 1 2 Size & Method Changeability Hierarchies 2 Coupling Quality Complexity 2 Dispersed Brain has Significant 2 1 Coupling Class Duplication 2 2 2 has 2 2 is 1 is 2 2 2 En Encapsulation Cohesion 2 has 2 2 Encapsulation Refused is Tradition Parent 2 Breaker andability Bequest Coupling Understandab En 1 1 has (subclass) 2 Complexity Size & 2 Futile Hierarchy
Relative Impact level (L/H) Relative Impact level (L/H) Relative Impact level (L/H) Relative Impact level (L/H) Relative Impact level (L/H) Analysis name Analysis name Impact class Impact class Analysis name Analysis name Impact class Impact class SCOMP ENC CPL COH HIE Blob Class class Blob Class class H L L Significant External Duplication system Significant External Duplication system H L L Significant Hierarchy Duplication hierarchy Significant Hierarchy Duplication hierarchy H L L H Significant Internal Duplication class Significant Internal Duplication class H L God Class system God Class system H H H L L Data Class system Data Class system L H L L Data Clumps system Data Clumps system L H Intensive Coupling class Intensive Coupling class H L H Dispersed Coupling system Dispersed Coupling system H H Shotgun Surgery Shotgun Surgery system system H Cyclic Dependencies (ADP Breakers) system Cyclic Dependencies (ADP Breakers) system H H Unnecessary Coupling system Unnecessary Coupling system L H Unstable Dependencies (SDP Breakers) system Unstable Dependencies (SDP Breakers) system L H Schizophrenic Class (SRP , ISP) Schizophrenic Class (SRP , ISP) class class H L H H Feature Envy class Feature Envy class L H H L L Refused Parent Bequest (LSP) hierarchy Refused Parent Bequest (LSP) hierarchy H H H Tradition Breaker (SRP) hierarchy Tradition Breaker (SRP) hierarchy H L L H SAP Breakers (DIP) system SAP Breakers (DIP) system L L H Distorted Hierarchy (deep and narrow) hierarchy Distorted Hierarchy (deep and narrow) hierarchy H L H ! Impact class Weight Impact class Weight Impact level Weight class 1 class 1 L 1 H 2 hierarchy 3 hierarchy 3 system 5 system 5 1 Assessment with metrics Stay tuned for the inFusion demo 2 3 inCode demos Assessment with Assessment with pictures tools
2 Polymetric views show up to 5 metrics Lanza, Ducasse, 2003 Use metrics in a Width metric visual context! Height metric Assessment with pictures Position metrics Color metric System Complexity shows class hierarchies Example attributes methods lines
1000+ classes in one picture... 11.000+ classes in one picture... ArgoUML, 2004 Java JDK 1.5, 2011 Trouble in paradise... Trouble 1: Heterogeneity
They are simply too many... Trouble 2: Edges are a pain...
) - : . s r e p a p h c r a e s e r d n a s o m e d n i y l n o k r o w s e g d E Polymetric Maps Beyond polymetric views... Visualize various design concerns. Reuse the layout!
Package Map: Layout Example: Package Maps Eclipse-JDT, 2010 Package Map: Design Problems Package Map: Coupling none many client (uses other classes) no severe Eclipse-JDT, 2010 none many Eclipse-JDT, 2010 affected by design problems provider (is used by other classes)
Package Map: Coupling A picture is worth a thousand words 3 Proverb Interactive! Eclipse-JDT, 2010 A demo is worth a thousand pictures Assessment with tools
inFusion inFusion 1 Quality Deficit becomes quantifiable 2 Detection of well-know design problems 3 Meaningful contextual advices 5 MLOC 4 Interactive visualizations . 3 1 It’s demo time! A demo is worth a thousand pictures
Design Quality Assessment in Practice inFusion Try out yourself! http://www.intooitus.com/products/infusion Radu Marinescu radum@cs.upt.ro
Recommend
More recommend