A Domain Analysis to Specify Design
Defects and Generate Detection Algorithms
Naouel Moha, Yann-Gaël Guéhéneuc, Anne-Françoise Le Meur, Laurence Duchien
Ptidej Team, GEODES, Université de Montréal, Canada
LIFL, INRIA Lille - Nord Europe / ADAM Team, Université de Lille, France
FASE’0829 March - 6 April, 2008
Moha ©
Context
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 2
Moha ©
Context
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 3
Moha © 4
� Design Patterns are “good” solutions to recurring design problems
� Design Defects (DDs)
� are “bad” solutions to recurring problems
� 2 categories:
� High-level (global) problems: antipatterns [Brown 98]
� Low-level (local) problems: code smells* [Fowler 99]
“ deviations from specifications or expectations which might lead to
failures in operation ”
* Some code smells can be considered as high-level DDs
What Kind of Defects ?
≠
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 5
What Kind of Defects ?
� 2 examples of high-level DDs [Brown 98]
� Blob (God Class)
“ Procedural-style design leads to one object with a
lion’s share of the responsibilities while most other
objects only hold data or execute simple processes ”
� Large controller class
� Many fields and methods with a low cohesion*
� Dependent on the data stored in associated
data classes
*How closely the methods are related to the instance
variables in the class.
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 6
� 2 examples of high-level DDs [Brown 98]
What Kind of Defects ?
� Spaghetti Code
“ Ad hoc software structure makes it difficult to extend
and optimize code. ”
� Procedural thinking in OO programming
� Lack of structure : no inheritance, no reuse, no
polymorphism
� Long methods process oriented with no
parameters and low cohesion
� Classes with procedural names
� Use of global variables for processing
Moha ©
Specification
Domain
Analysis
Detection
Processing
Validation
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 7
Method DECOR
Moha ©
Specification
Domain
Analysis
Detection
Processing
Validation
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 8
Method DECOR
Moha ©
Specification
Domain
Analysis
Detection
Processing
Validation
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 9
Method DECOR
Contributions
� Domain analysis of DDs and domain-specific language
� Explicit process for the specifications
� Validation : first study on both precision and recall
Moha ©
Specification
Domain
Analysis
Detection
Processing
Validation
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 10
Method DECOR
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 11
Domain AnalysisOn all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
Chapter 1
Descriptions of antipatterns
Chapter 1
Descriptions of antipatterns
�The Spaghetti Code is an
antipattern that is characteristic
of procedural thinking in object-
oriented programming. Spaghetti
Code is revealed by classes with
no structure, declaring long
methods with no parameters,
and utilising global variables for
processing. Names of classes
and methods may suggest
procedural programming.
Spaghetti Code does not exploit
and prevents the use of object-
orientation mechanisms,
polymorphism and inheritance.
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 12
Domain AnalysisOn all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
Chapter 1
Descriptions of antipatterns
Chapter 1
Descriptions of antipatterns
�The Spaghetti Code is an
antipattern that is characteristic
of procedural thinking in object-
oriented programming. Spaghetti
Code is revealed by classes with
no structure, declaring long
methods with no parameters,
and utilising global variables for
processing. Names of classes
and methods may suggest
procedural programming.
Spaghetti Code does not exploit
and prevents the use of object-
orientation mechanisms,
polymorphism and inheritance.
�Identification of Key Concepts
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 13
Domain AnalysisOn all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 14
Domain AnalysisOn all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
Moha ©
Specification
Domain
Analysis
Detection
Processing
Validation
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 15
Method DECOR
Moha ©
On all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
16
Specifications
SADSL (Software Architectural Defect Specification Language)
� Language based on a meta-model for specifying DDs
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms
CODESMELL define LongMethod as METRIC LOC_METHOD with VERY HIGH and 10.0 ;
CODESMELL define NoParameter as METRIC NMNOPARAM with VERY HIGH and 5.0 ;
CODESMELL define NoInheritance as METRIC DIT with 1 and 0.0 ;
CODESMELL define NoPolymorphism as STRUC NO_POLYMORPHISM ;
CODESMELL define ProceduralName as LEXIC CLASS_NAME with (Make, Create, Exec) ;
CODESMELL define GlobalVariable as STRUC USE_GLOBAL_VARIABLE ;
ANTIPATTERN define SpaghettiCode as {
((LongMethod INTER NoParameter) INTER (NoInheritance UNION NoPolymorphism))
INTER
(ProceduralName UNION UseGlobalVariable) } ;
Moha ©
On all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
17
Specifications
SADSL (Software Architectural Defect Specification Language)
� Language based on a meta-model for specifying DDs
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms
CODESMELL define LongMethod as METRIC LOC_METHOD with VERY HIGH and 10.0 ;
CODESMELL define NoParameter as METRIC NMNOPARAM with VERY HIGH and 5.0 ;
CODESMELL define NoInheritance as METRIC DIT with 1 and 0.0 ;
CODESMELL define NoPolymorphism as STRUC NO_POLYMORPHISM ;
CODESMELL define ProceduralName as LEXIC CLASS_NAME with (Make, Create, Exec) ;
CODESMELL define GlobalVariable as STRUC USE_GLOBAL_VARIABLE ;
ANTIPATTERN define SpaghettiCode as {
((LongMethod INTER NoParameter) INTER (NoInheritance UNION NoPolymorphism))
INTER
(ProceduralName UNION UseGlobalVariable) } ;
Moha © 18
Specifications
Meta-model SADDL (Software Architectural Defect Definition Language)
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms
On all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
Moha ©
Specification
Domain
Analysis
Detection
Processing
Validation
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 19
Method DECOR
Moha ©
Specification
Domain
Analysis
Detection
Algorithm
Generation
Validation
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 20
Method DECOR
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 21
Algorithm GenerationOn all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 22
Algorithm GenerationOn all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 23
Algorithm GenerationOn all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
Consistency and domain-specific analyses
- Verify that specifications are not inconsistent, redundant,
or incomplete
- Ex: 2 rules with same names but different properties
2 rules with different names but identical properties
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 24
Algorithm GenerationOn all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
Complexity : O((c+op) X n)
c : number of properties
op : number of operators
n : number of classes
SAD Framework
- Meta-model to represent OO programs
- Repository of metrics
- Services to analyse structural relationships
- Services to perform structural and lexical analyses
Moha ©
1 public class <CODESMELL>Detection
2 extends CodeSmellDetection
3 implements ICodeSmellDetection {
4 public Set performDetection() {
5 IClass c = iteratorOnClasses.next();
6 LOCofSetOfClasses.add(
7 Metrics.compute(<METRIC>, c));
8 ...
9 BoxPlot boxPlot = new BoxPlot(
10 <METRIC>ofSetOfClasses, <FUZZINESS>);
11 Map setOfOutliers =
12 boxPlot.<ORDINAL_VALUE>();
13 ...
14 suspiciousCodeSmells.add( new CodeSmell(
15 <CODESMELL>, setOfOutliers));
16 ...
17 return suspiciousCodeSmells;
18 }
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 25
Algorithm GenerationOn all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
�Visitor �Template
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 26
Algorithm GenerationOn all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
�Visitor �Generated Code
Moha ©
Specification
Domain
Analysis
Detection
Processing
Validation
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 27
Method DECOR
Moha ©
Specification
Domain
Analysis
Detection
Processing
Validation
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 28
Method DECOR
Moha © 29
Experiments
Goal : Validate the generated algorithms in terms of precision and recall
DetectionTime
RecallPrecisionDetected Defects
Existing
Defects
Nb of classes
Defects
2,45s100%88,6%44 (8,6%)39 (7,6%)
513
Blob
0,91s100%51,7%29 (5,6%)15 (2,9%)Functional Decomp.
0,23s100%60,5%76 (14,8%)46 (9,0%)Spaghetti Code
0,08s100%41,1%56 (10,9%)23 (4,5%)Swiss Army Knife
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms
Xerces: 71,217 LOC, 513 classes and 162 interfaces
On all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system
Moha © 30
Demonstration
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 31
Conclusion
� Method DECOR
Automate the generation of detection algorithms from specifications
written using a domain-specific language
� Contributions
� The domain-specific language defined from a domain analysis
� Explicit process for the generation of detection algorithms
� Validation in terms of precision and recall
� Future Work
� Experiments on other systems and defects
� Comparison with existing approaches
� Correction of defects (in progress)
Moha © A Domain Analysis to Specify Design Defects and Generate Detection Algorithms 32
Questions
Thanks for your attention !
Contact: [email protected]
http://www-etud.iro.umontreal.ca/~mohanaou
Moha © 33
Algorithm Generation
Box-plot for metrics with ordinal values
A Domain Analysis to Specify Design Defects and Generate Detection Algorithms
On all defects On each defect
1
Specification 2
Domain
Analysis
Vocabulary
Taxonomy
Operational
specifications
Brown et al. (1998)
Demeyer (2002)
Dudney (2003)
Fowler (1999)
Riel (1996)
Webster (1995)
Marinescu (2004)
Munro (2005)
Alikacem (2006)
Suspicious
classes
Text-based descriptions
of design defects
Marinescu (2004)
Alikacem (2006)
Travassos : manual detection (1999)
Tools: SmallLint, PMD, CROCOPAT
Detection
4
DECOR Method
Source code
of the system
Processing
3
Specifications Classes having
design defects
Validation
5Source code
of the system
Marinescu (2004)
Munro (2005)
On each system