Refactorings of Design Defects using
    Relational Concept Analysis

Naouel Moha, Amine Mohamed Rouane Hacene,
  Petko Valtchev, and Yann-Gaël Guéhéneuc

                         LORIA, France
            DIRO, University of Montréal, Canada
   LATECE, Université du Québec à Montréal, Montréal, Canada



                       ICFCA’08
    Montréal (Qc), Canada, February 25-28, 2008
Context




Moha ©    Refactorings of Design Defects using RCA   2
Context




Moha ©    Refactorings of Design Defects using RCA   3
Context




Moha ©    Refactorings of Design Defects using RCA   4
Context: Overall Process
             Textual descriptions
              of design defects


                 1       S                        3
                         P
                                            S
                         E
                                            U
                         C
                                            G
                         I
                                            G
                         F
                                            E
                         I
                                            S
                         C
                                            T
                         A
                                            I
                         T
                                            O
                         I
                                            N
                         O
                         N


                      Rules          Refactorings

                  2      D
                                            C     4
                                            O
                         E
                                            R
                         T
                                            R
                         E
                                            E
                         C
                                            C
                         T
                                            T
                         I
                                            I
                         O
                                            O
                         N
                                            N




                Classes having          Better
                design defects          Design
Moha ©       Refactorings of Design Defects using RCA   5
Context: Overall Process
             Textual descriptions
              of design defects


                 1       S                        3
                         P
                                            S
                         E
                                            U
                         C
                                            G
                         I
                                            G
                         F
                                            E
                         I
                                            S
                         C
                                            T
                         A
                                            I
                         T
                                            O
                         I
                                            N
                         O
                         N


                      Rules          Refactorings

                  2      D
                                            C     4
                                            O
                         E
                                            R
                         T
                                            R
                         E
                                            E
                         C
                                            C
                         T
                                            T
                         I
                                            I
                         O
                                            O
                         N
                                            N




                Classes having          Better
                design defects          Design
Moha ©       Refactorings of Design Defects using RCA   6
Context: Overall Process
  1-2. Specification and Detection of DDs
         More and more tools and techniques
            Actively researched area
            Method DECOR (Defect dEtection for CORrection) [Moha 06]

  3. Suggestion
  3 S      ti
         Manual identification of the modifications
            Time-, resource-consuming, error-prone activity
                 ,                  g,       p            y

  4. Correction
         Refactorings
                   g
         Technique used to change “the internal structure of software to make it
         easier to understand and cheaper to modify without changing its
         observable behavior”


Moha ©                         Refactorings of Design Defects using RCA     7
What Kind of Defects ?
   Design Patterns are “good” solutions to recurring design problems

   Design Defects (DDs)
         are “bad” solutions to recurring problems, Antipatterns [Brown 98]

         hinder d
         hi d development and maintenance by making programs h d t
                  l       t d     i t     b    ki            harder to
         comprehend and/or evolve

   DDs of interest: infected by low cohesion and high coupling
         Cohesion: how closely the methods are related to the variables in
         the class

         Coupling: the degree of its reliance on services provided by other
         classes



Moha ©                         Refactorings of Design Defects using RCA       8
What Kind of Defects ?
  An example of 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

                       High coupled with the data stored in
                       associated data classes




Moha ©                Refactorings of Design Defects using RCA          9
An Example
         Blob




         Before




Moha ©            Refactorings of Design Defects using RCA   10
An Example
                     How t correct th d f t ?
                     H   to      t the defect




                      Before                                 After
         Large and complex class               Large class becomes less complex
         Small data classes                    Data classes gain more behaviour
         Not object-oriented                   More object-oriented style
Moha ©                       Refactorings of Design Defects using RCA         11
An Example
         Redistribute l
         R di t ib t class members among existing classes ( ith possibly
                                b             i ti  l      (with    ibl
         new classes) to increase cohesion and–or decrease coupling




                 Before                                              After




Moha ©                    Refactorings of Design Defects using RCA           12
Contribution
  Suggestion
         RCA [Rouane 07, Ph.D. Thesis]
           Extension of FCA to relational d
           E       i   f             l i  l data
           Models the inter-object links and infers description logics role like
           relations between concepts
           RCA provides a suitable framework for clustering individuals along
           the properties they share and their links with other individuals
           Identify methods that share common fields and methods that call
           common methods          cohesive sets low coupled




Moha ©                         Refactorings of Design Defects using RCA     13
Contribution
  Suggestion
         RCA [Rouane 07, Ph.D. Thesis]
           Extension of FCA to relational d
           E       i   f             l i  l data
           Models the inter-object links and infers description logics role like
           relations between concepts
           RCA provides a suitable framework for clustering individuals along
           the properties they share and their links with other individuals
           Identify methods that share common fields and methods that call
           common methods          cohesive sets low coupled


  «D
   Develop an automated approach f suggesting d f t
       l         t    t d         h for  ti defect-
   correcting refactorings using RCA »



Moha ©                         Refactorings of Design Defects using RCA     14
An Example
                     How t correct th d f t ?
                     H   to      t the defect




                      Before                                 After
         Large and complex class               Large class becomes less complex
         Small data classes                    Data classes gain more behaviour
         Not object-oriented                   More object-oriented style
Moha ©                       Refactorings of Design Defects using RCA         15
An Example
         How t correct th d f t ?
         H   to      t the defect




         Blob                                   Cohesive Sets




Moha ©          Refactorings of Design Defects using RCA        16
An Example
                            How t correct th d f t ?
                            H   to      t the defect




                                      I = {W-borrow_date_Book, W-return_date_book}
                                      E = {}
  I = {‘check_Availability_Book()’}
  E = {check_Availability_Book()}



                                                         I = {call:c4}
                                                         E = {}

         I = {‘borrow_Book()’}        I = {‘reserve_Book()’, W-reserved_book}
         E = {borrow_Book()}          E = {reserve_Book()}



                              Lattice                                                 Cohesive Set




Moha ©                                     Refactorings of Design Defects using RCA                  17
An Example
                 How t correct th d f t ?
                 H   to      t the defect




         Cohesive Sets                                    After Refactoring *


                                               * Move Method Mode Field, Create Class
                                                      Method,     Field


Moha ©                   Refactorings of Design Defects using RCA                18
Suggestion




Moha ©       Refactorings of Design Defects using RCA   19
Suggestion
1.       RCF Modeling




Moha ©                  Refactorings of Design Defects using RCA   20
Suggestion
2.       RCA Al
             Algorithms
                  ith




Moha ©                    Refactorings of Design Defects using RCA   21
Suggestion
2.       RCA Al
             Algorithms
                  ith




              9
                  I = {W-library opened}
                      {W library_opened}
                  E={}

                                       10
                                            I = {‘open_Library()’}
                                            E = {open Library()}
                                                {open_Library()}
                     7
                         I = {‘close_Library()’}
                         E = {close_Library()}




Moha ©                              Refactorings of Design Defects using RCA   22
Suggestion
2.       RCA Al
             Algorithms
                  ith




Moha ©                    Refactorings of Design Defects using RCA   23
Suggestion
2.       RCA Al
             Algorithms
                  ith




             4
                 I = {‘check_Availability_Book()’}
                 E = {check_Availability_Book()}




                                                                                     19
                                                                                          I = {call:c4}
                                                                                          E={}


                                   3                                12
                                       I = {‘borrow_Book()’}             I = {‘reserve_Book()’,W-reserved_book}
                                       E = {borrow_Book() }              E = {reserve_Book()}




Moha ©                                 Refactorings of Design Defects using RCA                               24
Suggestion
 3.      Interpretation




            Cohesive Sets                                       After Refactoring



                                                  * Move Method Mode Field, Create Class
                                                         Method,     Field


Moha ©                      Refactorings of Design Defects using RCA                25
Experimental Study
  Tooling
         PADL to model source code and generate contexts
         Galicia to construct and visualize the concept lattices


  Experiments
  E    i   t
         Goal: evaluate the relevance of the cohesive sets suggested
         4 different open-source programs




Moha ©                         Refactorings of Design Defects using RCA   26
System   Experimental Study
                                                                               Nb of fields/       Nb of    Nb of real
                                                            Size (fields +
                            Blob Class          LOC                             methods          cohesive   cohesive     Precision
                                                              methods)
                                                                                 moved             sets       sets
                     DHTTransportUDPImpl        2,049       (42+66) 108         (27+32) 59         10           7          70%
V2.3.0.6
Azureus




                     DHTControlImpl             1,868       (47+80) 127         (35+62) 97         19          11          58%
                     TRTrackerBTAnnouncerImpl   1,393        (36+47) 83         (24+33) 57         16           5          31%
V0.7.1 V1.4 V1.2.1




                     LogBrokerMonitor           1,142       (29+105)134        (23+85) 108         31          17          55%
         ene Log4j




                     Category                   387           (9+53) 62          (8+44) 52         18           9          50%
                     IndexReader                236           (7+52) 59          (5+30) 35          4           2          50%
Nutch Luce




                     QueryParser                829          (36+48) 84         (24+37) 61         13          10          77%
                     FSNamesystem               710          (24+35) 59         (17+25) 42         18           9          50%
                     JobTracker                 555          (
                                                             (22+31) 53
                                                                   )            (
                                                                                (17+18) 35
                                                                                      )            11           8          73%
                                                                                                  Average Precision:       57%




         Moha ©                                       Refactorings of Design Defects using RCA                             27
Conclusion
    Contribution
         an approach that uses RCA to suggest refactorings to correct
         certain DDs in particular Blob
                 DDs,

    Validation
         4 different programs
         Relevant refactorings to improve programs

    Future Work
         -   Generalise to other DDs
         -   Assess more programs via our approach
         -   Discuss the suggested refactorings with their developers and
             apply them



Moha ©                        Refactorings of Design Defects using RCA      28
Questions
         Contact: mohanaou@iro.umontreal.ca
                  http://www-etud.iro.umontreal.ca/~mohanaou




         Thanks for your attention !

Moha ©                           Refactorings of Design Defects using RCA   29

ICFCA08.ppt

  • 1.
    Refactorings of DesignDefects using Relational Concept Analysis Naouel Moha, Amine Mohamed Rouane Hacene, Petko Valtchev, and Yann-Gaël Guéhéneuc LORIA, France DIRO, University of Montréal, Canada LATECE, Université du Québec à Montréal, Montréal, Canada ICFCA’08 Montréal (Qc), Canada, February 25-28, 2008
  • 2.
    Context Moha © Refactorings of Design Defects using RCA 2
  • 3.
    Context Moha © Refactorings of Design Defects using RCA 3
  • 4.
    Context Moha © Refactorings of Design Defects using RCA 4
  • 5.
    Context: Overall Process Textual descriptions of design defects 1 S 3 P S E U C G I G F E I S C T A I T O I N O N Rules Refactorings 2 D C 4 O E R T R E E C C T T I I O O N N Classes having Better design defects Design Moha © Refactorings of Design Defects using RCA 5
  • 6.
    Context: Overall Process Textual descriptions of design defects 1 S 3 P S E U C G I G F E I S C T A I T O I N O N Rules Refactorings 2 D C 4 O E R T R E E C C T T I I O O N N Classes having Better design defects Design Moha © Refactorings of Design Defects using RCA 6
  • 7.
    Context: Overall Process 1-2. Specification and Detection of DDs More and more tools and techniques Actively researched area Method DECOR (Defect dEtection for CORrection) [Moha 06] 3. Suggestion 3 S ti Manual identification of the modifications Time-, resource-consuming, error-prone activity , g, p y 4. Correction Refactorings g Technique used to change “the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior” Moha © Refactorings of Design Defects using RCA 7
  • 8.
    What Kind ofDefects ? Design Patterns are “good” solutions to recurring design problems Design Defects (DDs) are “bad” solutions to recurring problems, Antipatterns [Brown 98] hinder d hi d development and maintenance by making programs h d t l t d i t b ki harder to comprehend and/or evolve DDs of interest: infected by low cohesion and high coupling Cohesion: how closely the methods are related to the variables in the class Coupling: the degree of its reliance on services provided by other classes Moha © Refactorings of Design Defects using RCA 8
  • 9.
    What Kind ofDefects ? An example of 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 High coupled with the data stored in associated data classes Moha © Refactorings of Design Defects using RCA 9
  • 10.
    An Example Blob Before Moha © Refactorings of Design Defects using RCA 10
  • 11.
    An Example How t correct th d f t ? H to t the defect Before After Large and complex class Large class becomes less complex Small data classes Data classes gain more behaviour Not object-oriented More object-oriented style Moha © Refactorings of Design Defects using RCA 11
  • 12.
    An Example Redistribute l R di t ib t class members among existing classes ( ith possibly b i ti l (with ibl new classes) to increase cohesion and–or decrease coupling Before After Moha © Refactorings of Design Defects using RCA 12
  • 13.
    Contribution Suggestion RCA [Rouane 07, Ph.D. Thesis] Extension of FCA to relational d E i f l i l data Models the inter-object links and infers description logics role like relations between concepts RCA provides a suitable framework for clustering individuals along the properties they share and their links with other individuals Identify methods that share common fields and methods that call common methods cohesive sets low coupled Moha © Refactorings of Design Defects using RCA 13
  • 14.
    Contribution Suggestion RCA [Rouane 07, Ph.D. Thesis] Extension of FCA to relational d E i f l i l data Models the inter-object links and infers description logics role like relations between concepts RCA provides a suitable framework for clustering individuals along the properties they share and their links with other individuals Identify methods that share common fields and methods that call common methods cohesive sets low coupled «D Develop an automated approach f suggesting d f t l t t d h for ti defect- correcting refactorings using RCA » Moha © Refactorings of Design Defects using RCA 14
  • 15.
    An Example How t correct th d f t ? H to t the defect Before After Large and complex class Large class becomes less complex Small data classes Data classes gain more behaviour Not object-oriented More object-oriented style Moha © Refactorings of Design Defects using RCA 15
  • 16.
    An Example How t correct th d f t ? H to t the defect Blob Cohesive Sets Moha © Refactorings of Design Defects using RCA 16
  • 17.
    An Example How t correct th d f t ? H to t the defect I = {W-borrow_date_Book, W-return_date_book} E = {} I = {‘check_Availability_Book()’} E = {check_Availability_Book()} I = {call:c4} E = {} I = {‘borrow_Book()’} I = {‘reserve_Book()’, W-reserved_book} E = {borrow_Book()} E = {reserve_Book()} Lattice Cohesive Set Moha © Refactorings of Design Defects using RCA 17
  • 18.
    An Example How t correct th d f t ? H to t the defect Cohesive Sets After Refactoring * * Move Method Mode Field, Create Class Method, Field Moha © Refactorings of Design Defects using RCA 18
  • 19.
    Suggestion Moha © Refactorings of Design Defects using RCA 19
  • 20.
    Suggestion 1. RCF Modeling Moha © Refactorings of Design Defects using RCA 20
  • 21.
    Suggestion 2. RCA Al Algorithms ith Moha © Refactorings of Design Defects using RCA 21
  • 22.
    Suggestion 2. RCA Al Algorithms ith 9 I = {W-library opened} {W library_opened} E={} 10 I = {‘open_Library()’} E = {open Library()} {open_Library()} 7 I = {‘close_Library()’} E = {close_Library()} Moha © Refactorings of Design Defects using RCA 22
  • 23.
    Suggestion 2. RCA Al Algorithms ith Moha © Refactorings of Design Defects using RCA 23
  • 24.
    Suggestion 2. RCA Al Algorithms ith 4 I = {‘check_Availability_Book()’} E = {check_Availability_Book()} 19 I = {call:c4} E={} 3 12 I = {‘borrow_Book()’} I = {‘reserve_Book()’,W-reserved_book} E = {borrow_Book() } E = {reserve_Book()} Moha © Refactorings of Design Defects using RCA 24
  • 25.
    Suggestion 3. Interpretation Cohesive Sets After Refactoring * Move Method Mode Field, Create Class Method, Field Moha © Refactorings of Design Defects using RCA 25
  • 26.
    Experimental Study Tooling PADL to model source code and generate contexts Galicia to construct and visualize the concept lattices Experiments E i t Goal: evaluate the relevance of the cohesive sets suggested 4 different open-source programs Moha © Refactorings of Design Defects using RCA 26
  • 27.
    System Experimental Study Nb of fields/ Nb of Nb of real Size (fields + Blob Class LOC methods cohesive cohesive Precision methods) moved sets sets DHTTransportUDPImpl 2,049 (42+66) 108 (27+32) 59 10 7 70% V2.3.0.6 Azureus DHTControlImpl 1,868 (47+80) 127 (35+62) 97 19 11 58% TRTrackerBTAnnouncerImpl 1,393 (36+47) 83 (24+33) 57 16 5 31% V0.7.1 V1.4 V1.2.1 LogBrokerMonitor 1,142 (29+105)134 (23+85) 108 31 17 55% ene Log4j Category 387 (9+53) 62 (8+44) 52 18 9 50% IndexReader 236 (7+52) 59 (5+30) 35 4 2 50% Nutch Luce QueryParser 829 (36+48) 84 (24+37) 61 13 10 77% FSNamesystem 710 (24+35) 59 (17+25) 42 18 9 50% JobTracker 555 ( (22+31) 53 ) ( (17+18) 35 ) 11 8 73% Average Precision: 57% Moha © Refactorings of Design Defects using RCA 27
  • 28.
    Conclusion Contribution an approach that uses RCA to suggest refactorings to correct certain DDs in particular Blob DDs, Validation 4 different programs Relevant refactorings to improve programs Future Work - Generalise to other DDs - Assess more programs via our approach - Discuss the suggested refactorings with their developers and apply them Moha © Refactorings of Design Defects using RCA 28
  • 29.
    Questions Contact: [email protected] http://www-etud.iro.umontreal.ca/~mohanaou Thanks for your attention ! Moha © Refactorings of Design Defects using RCA 29