Design Quality Assessment in Practice my two hats... Radu Marinescu radum@cs.upt.ro Associate Professor since 006 Co-Founder and Head since 003 http://www.intooitus.com/ Co-Founder (008)
Assessment with pictures Assessment with metrics Assessment with metrics 3 Assessment with tools Software is complex. 9% Succeeded forward engineering 8% Failed 53% Challenged The Standish Group, 004
forward engineering When, due to constraints, I design quickly and dirty, my project is loaded with technical debt. W.Cunningham, 99 actual development How can I control this...? You cannot control what you cannot measure. Tom de Marco
Metrics compress 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 TCC - tight class cohesion Lorenz, Kidd, 994 Chidamber, Kemerer, 994
Trouble in paradise... Trouble : Thresholds
Metric Value LOC 3575 NOM? 368 NOC 384 CYCLO 5579 NOP 9 FANOUT 8590 Are these numbers normal? We need means to compare. We need comparable metrics.
Overview Pyramid provides a metrics overview. Marinescu, Lanza Overview Pyramid provides a metrics overview. Marinescu, Lanza Inheritance 0.5 CYCLO 9.7 LOC 9.4 NOM ANDC 0.3 AHH 0. 0. NOP 9 NOC 384 368 NOM 3575 58 5579 8590 48 CALLS 0.56 FANOUT 0.5 CYCLO 9.7 LOC 9.4 NOM ANDC 0.3 AHH 0. 0. NOP 9 NOC 384 368 NOM 3575 58 5579 8590 48 CALLS 0.56 FANOUT Size Communication Size Overview Pyramid provides a metrics overview. Marinescu, Lanza LOW Java AVG HIGH LOW C++ AVG HIGH CYCLO/LOC 0.6 0.0 0.4 0.0 0.5 0.30 0.5 CYCLO 9.7 LOC 9.4 NOM ANDC 0.3 AHH 0. 0. NOP 9 NOC 384 368 NOM 3575 58 5579 8590 48 CALLS 0.56 FANOUT LOC/NOM NOM/NOC... 7 0 3 4 7 0 4.000+ OSS projects 500.000.000+ LOC 5 4 0 9 6 5
The Overview Pyramid provides a metrics overview. Marinescu, Lanza The Overview Pyramid provides a metrics overview. Marinescu, Lanza 0.5 CYCLO 9.7 LOC 9.4 NOM ANDC 0.3 AHH 0. 0. NOP 9 NOC 384 368 NOM 3575 58 5579 8590 48 CALLS 0.56 FANOUT 0.5 CYCLO 9.7 LOC 9.4 NOM ANDC 0.3 AHH 0. 0. NOP 9 NOC 384 368 NOM 3575 58 5579 8590 48 CALLS 0.56 FANOUT close to high close to average close to low The Overview Pyramid provides a metrics overview. Marinescu, Lanza Trouble : 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, 977
Capture violations of design principles & best practices in an automatic manner... An example... Detection Strategies are metric-based queries to detect design flaws. Marinescu God Classes tend to centralize the intelligence of the, to do everything and to use data from small data-classes. A.Riel, 996 Rule METRIC > Threshold AND Quality problem Rule METRIC < Threshold
God Classes tend to centralize the intelligence of the, to do everything and to use data from small data-classes. God Classes centralize the intelligence of the, do everything and use data from small data-classes. God Classes are complex, are not cohesive, access external data. A God Class centralizes too much intelligence in the. Class uses directly more than a few attributes of other classes ATFD > FEW Marinescu, Lanza Compose metrics into queries using logical operators Functional complexity of the class is very high WMC VERY HIGH Class cohesion is low AND GodClass TCC < ONE THIRD
Shotgun Surgery Marinescu, Lanza Shotgun Surgery Marinescu, Lanza uses is Feature Envy Data Class (partial) Feature Envy uses Data Class Intensive Coupling Dispersed Coupling God Class Brain Class Brain Method Significant Duplication Intensive Coupling Dispersed Coupling God Class Brain Class is is Brain Method is partially Significant Duplication Refused Parent Bequest Tradition Breaker Refused Parent Bequest is Tradition Breaker (subclass) Futile Hierarchy Futile Hierarchy Identity Disharmonies Collaboration Disharmonies Classification Disharmonies Identity Disharmonies Collaboration Disharmonies Classification Disharmonies Measure quality deficit based on design problems Measure quality deficit based on design problems Quality Understandability Changeability Reusability Reusability Hierarchies uses is Shotgun Surgery Cohesion (partial) Feature Envy uses Data Class Size & Complexity Encapsulation Coupling Cohesion Hierarchies Quality Understand dability Changeability Size & Complexity Encapsulation Coupling Intensive Coupling Dispersed Coupling Refused Parent Bequest God Class Brain Class is is is Tradition Breaker Futile Hierarchy is partially Brain Method (subclass) Significant Duplication
Analysis name Impact class Analysis name Impact class Relative Impact level (L/H) SCOMP ENC CPL COH HIE Blob Class Significant External Duplication Significant Hierarchy Duplication Significant Internal Duplication God Class Data Class Data Clumps Intensive Coupling Dispersed Coupling Shotgun Surgery Cyclic Dependencies (ADP Breakers) Unnecessary Coupling Unstable Dependencies (SDP Breakers) Schizophrenic Class (SRP, ISP) Feature Envy Refused Parent Bequest (LSP) Tradition Breaker (SRP) SAP Breakers (DIP) Distorted Hierarchy (deep and narrow) class hierarchy class class class class hierarchy hierarchy hierarchy Blob Class Significant External Duplication Significant Hierarchy Duplication Significant Internal Duplication God Class Data Class Data Clumps Intensive Coupling Dispersed Coupling Shotgun Surgery Cyclic Dependencies (ADP Breakers) Unnecessary Coupling Unstable Dependencies (SDP Breakers) Schizophrenic Class (SRP, ISP) Feature Envy Refused Parent Bequest (LSP) Tradition Breaker (SRP) SAP Breakers (DIP) Distorted Hierarchy (deep and narrow) class H L L H L L hierarchy H L L H class H L H H H L L L H L L L H class H L H H H H H H L H L H class H L H H class L H H L L hierarchy H H H hierarchy H L L H L L H hierarchy H L H Impact class Weight class hierarchy 3 5 Impact class Weight class hierarchy 3 5 Impact level Weight L H Stay tuned for the infusion demo incode demos! Assessment with pictures Assessment with metrics 3 Assessment with tools
Assessment with pictures Polymetric views show up to 5 metrics Use metrics in a visual context! Height metric Position metrics Width metric Lanza, Ducasse, 003 Color metric System Complexity shows class hierarchies Example attributes methods lines
000+ classes in one picture....000+ classes in one picture... ArgoUML, 004 Java JDK.5, 0 Trouble in paradise... Trouble : Heterogeneity
Trouble : Edges are a pain... They are simply too many...
Edges work only in demos and research papers. :-) Beyond polymetric views... Polymetric Maps Visualize various design concerns. Reuse the layout!
Package Map: Layout Example: Package Maps Eclipse-JDT, 00 Package Map: Design Problems Package Map: Coupling none many client (uses other classes) no severe affected by design problems Eclipse-JDT, 00 none many provider (is used by other classes) Eclipse-JDT, 00
Package Map: Coupling A picture is worth a thousand words Interactive! Eclipse-JDT, 00 3 A demo is worth a thousand pictures Assessment with tools Proverb
infusion infusion Quality Deficit becomes quantifiable Detection of well-know design problems 3 Meaningful contextual advices 4 Interactive visualizations 3.5 MLOC A demo is worth a thousand pictures It s demo time!
Try out infusion yourself! Design Quality Assessment in Practice http://www.intooitus.com/products/infusion Radu Marinescu radum@cs.upt.ro