SlideShare a Scribd company logo
1 of 74
Download to read offline
AOP refactoring and code smells




     Towards a Catalogue of Refactorings and Code Smells
                         for AspectJ
                                       AOP Seminar - Session 15


                                                   Sander Mak

                             Center for Software Technology, Universiteit Utrecht


                                               Januari 15, 2007




                                  Center for Software Technology                    Sander Mak
AOP refactoring and code smells


  Outline


        Introduction
    1


        AOP and refactoring
    2


        The paper
    3


        Other approaches
    4


        Conclusion
    5


        Questions
    6




                                  Center for Software Technology   Sander Mak
AOP refactoring and code smells > Introduction


 In the beginning




 Inļ¬‚uential book by Martin Fowler (1999)

 Preceded by PhD work of William Opdyke
 (1992)

 Many papers on OO refactoring followed




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > Introduction


 Deļ¬ne refactoring

    What is refactoring?

    Subtitle of Fowlerā€™s book: improving design of existing code

    Refactoring is the process of changing a software system in such a way
    that it does not alter the external behavior of the code, yet improves
    its internal structure. Martin Fowler




                                 Center for Software Technology       Sander Mak
AOP refactoring and code smells > Introduction


 Deļ¬ne refactoring

    What is refactoring?

    Subtitle of Fowlerā€™s book: improving design of existing code

    Refactoring is the process of changing a software system in such a way
    that it does not alter the external behavior of the code, yet improves
    its internal structure. Martin Fowler

           Behavior preserving
           Structure changing
           Improving design


    Refactorings are small transformation steps for code

                                 Center for Software Technology       Sander Mak
AOP refactoring and code smells > Introduction


 Why refactor?

           Maintainable code
                   More understandable code
                   Compliance to standard practices
                   Speeds up development
           Reusable code, separate structure from app. logic
           Pinpointing bugs becomes easier
           Essential ingredient of agile processes
                   Source code is the main communication medium




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > Introduction


 Why refactor?

           Maintainable code
                   More understandable code
                   Compliance to standard practices
                   Speeds up development
           Reusable code, separate structure from app. logic
           Pinpointing bugs becomes easier
           Essential ingredient of agile processes
                   Source code is the main communication medium

    XP Rule
    ā€Refactor Mercilesslyā€

    Summarizing: to increase both quality and productivity of a developer


                                 Center for Software Technology       Sander Mak
AOP refactoring and code smells > Introduction


 When to refactor?



         Rule of Three
                 If you do something similar 3 times in a
                 row... refactor it!
         When adding new functionality
                 ļ¬t it in elegantly by refactoring
                 otherwise risk spaghetti-code...
         During code review
         Everytime you ļ¬nd a code smell




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > Introduction


 Code smells


    A code smell is a heuristic that might indicate the need for refactoring.

    Examples:

      Feature envy                       a class is more concerned with other classesā€™
                                         data than with its own
      Long parameter list                pass enough parameters to let a method ļ¬nd what
                                         it needs, but nothing more
      Temporary ļ¬eld                     class member is used where local local scope would
                                         have been appropriate
    These have been published along with refactorings to cure the smells



                                 Center for Software Technology                     Sander Mak
AOP refactoring and code smells > AOP and refactoring


 AOP and refactoring


    Observation:
    AOP and refactoring share a common high-level goal:
      Creating systems that are easier to understand and maintain




                                 Center for Software Technology     Sander Mak
AOP refactoring and code smells > AOP and refactoring


 AOP and refactoring


    Observation:
    AOP and refactoring share a common high-level goal:
      Creating systems that are easier to understand and maintain

           Simplicity - less errors
           Clarity - communicate intentions
           Brevity - conciseness over verbosity

    The cardinal rule of writing unmaintainable code is to specify each fact
    in as many places as possible and in as many ways as possible.
    - Roedy Green in: How to write unmaintainable code



                                 Center for Software Technology         Sander Mak
AOP refactoring and code smells > AOP and refactoring


 Refactoring extended
    AOP can take over where OO refactoring ends:




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > AOP and refactoring


 Good style


    When there are several ways to solve a problem,
    how do we pick the right wayTM ?

           Follow intentions of language
                  Languages dictate composition mechanisms
                  Ideally: each concern separated, but you cannot separate what you
                  cannot compose later
           Experience
           Follow good style rules
                  E.g. as documented in catalogue
                  Avoiding code smells




                                 Center for Software Technology                Sander Mak
AOP refactoring and code smells > The paper


 The paper

    Towards a catalogue of refactorings and code smells for AspectJ

    Based on PhD work of M. Monteiro, written with his supervisor J.
    Fernandes

    Premises of the paper:
           There is no notion of good AOP style yet
       1


           This can be improved by providing a catalogue of refactorings and
       2

           smells
           Toolsupport for integrating AOP with refactoring is lacking
       3




    Preservation of intention over preservation of behavior


                                 Center for Software Technology          Sander Mak
AOP refactoring and code smells > The paper


 The paper


    Three categories of refactorings:
           OO ā†’ AspectJ (10)
       1

           AspectJ internal refactorings (6)
       2

                  part of OO refactorings can be ported to aspects
                  other refactorings handle new concepts, e.g. pointcuts
           Inter-aspect refactorings (11)
       3


    Idea is to sequentially compose these refactorings.

    Fragile pointcut problem is not addressed explicitly




                                 Center for Software Technology            Sander Mak
AOP refactoring and code smells > The paper


 The paper

    What is not in the paper:

           Formalism for AOP refactoring
                  Authors follow format introduced by Fowler:

    Typical situation, Recommended action, Motivation, Mechanics,
    Examples

           Tool support
                  Neither for application ..
                  .. nor detection
           Metrics
                  Mentions related work for AOP complexity metrics though



                                 Center for Software Technology             Sander Mak
AOP refactoring and code smells > The paper


 Approach

    Empirical: take existing, appropriate codebases and experiment.

    Attempt 1
    A workļ¬‚ow program was decomposed into use cases. Use cases were
    captured in AOP style.
           Four AOP refactorings could be described
           Invaluable experience was gained
           Monolithic aspect
           Aspect was not exemplary for AspectJ usage
    Conclusion: good OO style pre-condition for extracting aspects



                                 Center for Software Technology       Sander Mak
AOP refactoring and code smells > The paper


 Approach


    Empirical: take existing, appropriate codebases and experiment.

    Attempt 2
    AOP design pattern implementations of Hanneman & Kiczales were
    studied. Goal: try to describe transformation of OO ā†’ AOP in terms
    of refactorings
           Great variety of diļ¬€erent aspects
           No domain knowledge necessary
           Some refactorings were too case speciļ¬c (this needs to be
           recognized)



                                 Center for Software Technology        Sander Mak
AOP refactoring and code smells > The paper


 Approach



    Considerations regarding this empirical approach:
           Result: realworld solutions to realworld problems
           It worked for OO, so why not for AOP
           Result may be skewed because of case selection
           E.g. exception handling was not considered
           Generality of ļ¬ndings is debatable




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > The paper


 OO to AOP refactoring


    Replace implements with declare parents
    Problem: interface adds secondary role to a class




    Usually combined with inline interface with aspect



                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > The paper


 AOP internal refactoring
    Introduce aspect protection
    Problem: restrict usage of inter-type ļ¬eld to aspect and its sub-aspects




                                 Center for Software Technology         Sander Mak
AOP refactoring and code smells > The paper


 AOP internal refactoring


    Minor criticism:
           A bit of a hack
           Very speciļ¬c to AspectJ




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > The paper


 AOP internal refactoring


    Minor criticism:
           A bit of a hack
           Very speciļ¬c to AspectJ


    In comparison, a refactoring like replace inter-type ļ¬eld with aspect
    map is much more general .


    Also, OO refactorings can be used in aspects (extract method,
    intra-method refactorings)



                                 Center for Software Technology      Sander Mak
AOP refactoring and code smells > The paper


 AOP internal refactoring


    Minor criticism:
           A bit of a hack
           Very speciļ¬c to AspectJ


    In Remark by Wouter
       comparison, a refactoring like replace inter-type ļ¬eld with aspect
    map the ā€Introducegeneral .Protectionā€ section, you might want to have
       In is much more Aspect
       some modiļ¬er that takes care of the protection?

    Also, OO refactorings canthis used in aspects (extract method,
       Sure, that would make be refactoring unnecessary
    intra-method refactorings)



                                 Center for Software Technology      Sander Mak
AOP refactoring and code smells > The paper


 AOP internal refactoring


    Minor criticism:
          A bit of a hack
       Remarkspeciļ¬c to AspectJ
          Very by Elmar
       Some of the refactorings like ā€Introduce Aspect Protectionā€ seem to
       thank their existance to (unclear, incomplete, faulty) semantics of
    In comparison, a refactoring like replace inter-type ļ¬eld with aspect
       AspectJ. Take for example the ā€Introduce Aspect Protectionā€ Canā€™t
    map is much more general .
       we argue that some of these semantics for AspectJ should change,
       instead of making a work around using refactoring?
    Also, OO refactorings can be used in aspects (extract method,
       Indeed. Still the existance of this refactoring in the catalogue
    intra-method refactorings)
       makes a programmer aware of the issues.



                                 Center for Software Technology      Sander Mak
AOP refactoring and code smells > The paper


 AOP internal refactoring


    Replace inter-type ļ¬eld with aspect map
    Problem: aspect introduces additional state to a class, but it might
    not need it all the time, so resources are wasted
           Inter-type declarations aļ¬€ect all instances of a class
           Inter-type declarations last a lifetime




                                 Center for Software Technology            Sander Mak
AOP refactoring and code smells > The paper


 AOP internal refactoring


    Replace inter-type ļ¬eld with aspect map
    Problem: aspect introduces additional state to a class, but it might
    not need it all the time, so resources are wasted
           Inter-type declarations aļ¬€ect all instances of a class
           Inter-type declarations last a lifetime


    Solution: Maintain mapping to additional data in aspect, re-route all
    ļ¬eld accesses to the aspect

    Highly similar to relationship aspects! This refactoring constitutes
    moving from static to dynamic relations.


                                 Center for Software Technology            Sander Mak
AOP refactoring and code smells > The paper


 AOP generalisation refactoring


    Goal of these refactorings: transform an application speciļ¬c aspect
    into a generalized, reusable aspect.

    Again, much of the OO idiom can be ported to aspects, with subtle
    diļ¬€erences:


           There is no inheritance/overriding between advice (as opposed to
           methods)
           Therefore it sometimes necessary to push down advice
           Weaving behavior might be surprising




                                 Center for Software Technology         Sander Mak
AOP refactoring and code smells > The paper


 AOP generalisation refactoring

    Pull up inter-type declaration
    Problem: inter-type declaration is better placed in a super aspect (not
    because of duplication!)

    Issues:
           Targets of inter-type declarations receive an instance of the
           declaration per aspect
           When refactoring identical inter-type ļ¬elds to super aspect, only
           one instance is created at weaving time
           Compare to making a ļ¬eld static

    With more than one sub aspect most likely not behavior preserving


                                 Center for Software Technology            Sander Mak
AOP refactoring and code smells > The paper


 AOP code smells



    Describe what code should not be like
           Smells can lead to speciļ¬c refactorings
           Smells are somewhat subjective
           Some of Fowlerā€™s smells hint at cross-cutting concerns
                  Captured by ā€™extract feature into aspectā€™ refactoring


    This paper describes 3 smells




                                 Center for Software Technology           Sander Mak
AOP refactoring and code smells > The paper


 AOP code smells
    Smell 1: double personality
           Class has multiple roles
           Recall superimposed roles in design patterns
           Secondary role might be cross-cutting
    Smell 2: abstract classes
           Abstract classes need to be extended
           Preventing the extending class to inherit from other classes
           Default implementations can be provided by inter-type
           declarations
    Smell 3: aspect laziness
           Overuse of inter-type declarations
           Real AOP smell
                                 Center for Software Technology           Sander Mak
AOP refactoring and code smells > Other approaches


 Automation


    Catalogues are cool, but...

    All these smells and refactorings deal with concerns that are
    inherently scattered

    I think automation is essential to:
           Detect OO ā†’ AOP refactorings
       1


           Detect refactorings within aspects
       2


           Apply AOP refactorings
       3




    This sessionā€™s paper agrees, but does not contribute



                                 Center for Software Technology     Sander Mak
AOP refactoring and code smells > Other approaches


 AOP code smells

    Related work on code smells:


                     Detecting bad smells in AspectJ Piveta et al.



           Describes 5 AOP smells
           Provides algorithm to ļ¬nd these
           A prototype implementation is available
           Contains a case study on three AspectJ systems


    Algorithms are not very sophisticated


                                 Center for Software Technology      Sander Mak
AOP refactoring and code smells > Other approaches


 AOP code smells



    Described smells and algorithms:
           Anonymous pointcut deļ¬nitions
       1


           Large aspects
       2


           Lazy aspects
       3


           Feature envy (deļ¬ned as: class containing pointcut)
       4


           Abstract method introduction
       5




    Implemented in plugin for AspectJ eclipse extension




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > Other approaches


 AOP code smells

Architecture plugin
    Described smells and algorithms:
           Anonymous pointcut deļ¬nitions
       1


           Large aspects
       2


           Lazy aspects
       3


           Feature envy (deļ¬ned as: class containing pointcut)
       4


           Abstract method introduction
       5




    Implemented in plugin for AspectJ eclipse extension




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > Other approaches


 Anonymous pointcut detection




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > Other approaches


 Anonymous pointcut detection




    In other words: all pointcuts containing AspectJ pointcut primitives
                                 Center for Software Technology        Sander Mak
AOP refactoring and code smells > Other approaches


 Abstract method introductions
    Abstract methods demand implementation, creates unnecessary
    coupling between aspect and class




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > Other approaches


 Case study



    Programs analyzed:
           AspectJ examples
           Design pattern implementations Hannemann & Kiczales
           GlassBox inspector (J2EE monitoring app)

    Results: very little smells found, besides many anonymous pointcuts

    .. these are not necessary bad, most of them are used once




                                 Center for Software Technology       Sander Mak
AOP refactoring and code smells > Other approaches


 Case study
    Output analysis


    Programs analyzed:
           AspectJ examples
           Design pattern implementations Hannemann & Kiczales
           GlassBox inspector (J2EE monitoring app)

    Results: very little smells found, besides many anonymous pointcuts

    .. these are not necessary bad, most of them are used once




                                 Center for Software Technology       Sander Mak
AOP refactoring and code smells > Other approaches


 Smell metrics
    Mentioned in previous paper:
                           Metrics based refactoring Simon et al.
    More formalized metrics, and graphical representation.




                                 Center for Software Technology     Sander Mak
AOP refactoring and code smells > Other approaches


 Smell metrics
    Mentioned in previous paper:
                           Metrics based refactoring Simon et al.
    More formalized metrics, and graphical representation.




    Output analysis
    Not aspect oriented (yet)




                                 Center for Software Technology     Sander Mak
AOP refactoring and code smells > Other approaches


 Refactoring tool


    AspectJ Refactoring Tool (ART), Iwamoto et al.

    Works on PDGs, not on ASTs:
           Program Dependence Graph
           Existing formalism
           Like control ļ¬‚ow graph
           With additional information on data

    Automates application of refactorings




                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > Other approaches


 Refactoring tool


 24 refactorings are
 proposed:
         OO ā†’ AOP
         refactorings
         internal AOP
         refactorings
 there is ample overlap with
 session paper

 Diļ¬€erence: refactorings are
 composed with laws



                                 Center for Software Technology   Sander Mak
AOP refactoring and code smells > Other approaches


 Refactoring tool

                                                     Example law, move ļ¬eld to aspect:
 24 refactorings are
 proposed:
         OO ā†’ AOP
         refactorings
         internal AOP
         refactorings
 there is ample overlap with
 session paper

 Diļ¬€erence: refactorings are
 composed with laws



                                 Center for Software Technology                          Sander Mak
AOP refactoring and code smells > Other approaches


 Aspect Mining



    So far weā€™ve seen tools to:
           Find code smells
           Find OO refactorings
           Apply refactorings

    In order to ļ¬nd OO ā†’ AOP refactorings, we need something like
    aspect mining.




                                 Center for Software Technology     Sander Mak
AOP refactoring and code smells > Other approaches


 Aspect Mining



    So far weā€™ve seen tools to:
          Find code smells
       Question: Rinse
       Refactoring refactorings
          Find OO code into aspects can become a little tedious when trying
       to Apply refactorings
           track down all classes involved in say a observer pattern. There is
       research being done in aspect mining techniques [1] do you think with
    In the proposed catalogue of refactorings and code smells for AspectJ and
       order to ļ¬nd OO ā†’ AOP refactorings, we need something like
    aspect mining.mining techniques we could come anything close to the
       these aspect
       current support for refactorings in IDEs for normal OO concerns?
       [1]: Applying and combining three diļ¬€erent aspect Mining Techniques



                                 Center for Software Technology          Sander Mak
AOP refactoring and code smells > Other approaches


 Aspect Mining



    Approach created at TU Delft, combines and compares three aspect
    mining techniques:
           Fan-in analysis
       1


           Identiļ¬er analysis
       2


           Dynamic analysis
       3




    Each of these is tested on JHotDraw, a graphics application created
    to showcase good usage of design patterns.




                                 Center for Software Technology      Sander Mak
AOP refactoring and code smells > Other approaches


 Aspect Mining


    Fan-in analysis
           Count number of locations from which control is passed into a
           module
           In OO: fan-in for method M is number of distinct bodies that can
           call M
           Idea: if a method is called from many places, it is probably
           cross-cutting
           Certain treshold needs to be in place (experimentally determined
           value: 10)
           Analysis excludes getter/setters and utility methods like toString()



                                 Center for Software Technology            Sander Mak
AOP refactoring and code smells > Other approaches


 Aspect Mining


    Identiļ¬er analysis
           Lexical analysis of identiļ¬ers in code
           Split composed name into single words
           Take stem of words
           Group common words
           If a group is scattered over multiple classes/methods: it is
           probably a cross-cutting concern
           Depends on naming conventions




                                 Center for Software Technology           Sander Mak
AOP refactoring and code smells > Other approaches


 Aspect Mining



    Dynamic analysis
           Analyse execution traces of (instrumented) program
           Run program with diļ¬€erent scenarios (use cases)
           Keep track of locality in code (call stack)
           Analyse which methods relate to which use case and which are
           generic
           Depends on well-chosen scenarios




                                 Center for Software Technology           Sander Mak
AOP refactoring and code smells > Other approaches


 Aspect Mining


    A framework was devised to test all analyses. Some concerns as
    detected:
           Contract enforcement (pre-condition checking)
           Undo
           Observer pattern
           Persistance (read/write functionality)

    All three techniques found the most common concerns. Fan-in was
    found to be suitable for larger applications, and the techniques were
    complementary for uncommon concerns.
    No production quality tool was implemented.


                                 Center for Software Technology         Sander Mak
AOP refactoring and code smells > Other approaches


 Other tools/methods


      Rolebased Refactoring                  Hannemann & Kiczales
                                             Programmer maps conceptual concerns to code
                                             fragments. Tools helps with mapping, and
                                             with manipulating the code fragments.
      Aspect mining tool                     Lexical analysis and type based analysis, with
                                             stand alone visualizer. Based on modiļ¬ed ajc
      FEAT/ConcernMapper                     Eclipse plugin to navigate/analyze/refactor
                                             AspectJ code.
      Concern Manipulation                   Eclipse plugin (originally by IBM) to manage
      Environment                            and build concerns in code. No analysis.




                                 Center for Software Technology                     Sander Mak
AOP refactoring and code smells > Conclusion


 Concluding remarks


           The paper gives a thorough description of a catalogue
           Unfortunately, it does not consider much more
                  Especially more could be said on toolsupport
           Moving refactoring from OO to AOP brings in a lot of subtleties
           (aspects vs. classes)
           AOP refactoring research ļ¬eld is fairly new and open
           There are many (research)tools, but
                  Its not very clear how these all relate and how powerful they are
                  To answer Rinseā€™s question: I donā€™t think it comes near legacy
                  refactoring support yet




                                 Center for Software Technology                   Sander Mak
AOP refactoring and code smells > Conclusion


 Concluding remarks


           The paper gives a thorough description of a catalogue
           Unfortunately, it does not consider much more
                  Especially more could be said on toolsupport
       Masterā€™s thesis
         Moving refactoring from OO to AOP brings in a lot of subtleties
       May be someone should take on this challenge and survey the
         (aspects vs. classes)
       AOP refactoring tools ļ¬eld and create the ultimate formalism and
       tool for refactoring research ļ¬eld is fairly new and open
         AOP AOP refactoring :-) ?
         There are many (research)tools, but
                  Its not very clear how these all relate and how powerful they are
                  To answer Rinseā€™s question: I donā€™t think it comes near legacy
                  refactoring support yet




                                 Center for Software Technology                   Sander Mak
AOP refactoring and code smells > Questions


 Question: Wouter


    I think that some of the problems could be solved better with some
    Java and/or AspectJ changes, for example:
    In section 4.2 ā€generalize target typeā€ refactoring is used:
       private interface NewTypeClass {}
       declare parents: SomeClass implements NewTypeClass;
    This makes the code better by deļ¬ning a role/type that the class then
    ā€™implementsā€™. But the Interface/implements constructs of Java arenā€™t
    really designed for modeling roles right? I think that there might be a
    need for some stronger or better typing system than this (maybe
    something like Haskellā€™s?).




                                 Center for Software Technology         Sander Mak
AOP refactoring and code smells > Questions


 Question: Wouter


    I think that some of the problems could be solved better with some
    Java and/or AspectJ changes, for example:
    In section 4.2 ā€generalize target typeā€ refactoring is used:
       private interface NewTypeClass {}
       declare parents: SomeClass implements NewTypeClass;
    This makes the code better by deļ¬ning a role/type that the class then
    ā€™implementsā€™. But the Interface/implements constructs of Java arenā€™t
    really designed for modeling roles right? I think that there might be a
    need for some stronger or better typing system than this (maybe
    something like Haskellā€™s?).


    Letā€™s discuss

                                 Center for Software Technology         Sander Mak
AOP refactoring and code smells > Questions


 Question: Wouter


    Can you elaborate a bit on the main items that you think could be
    added to Java or aspectJ that will help the refactoring?




                                 Center for Software Technology         Sander Mak
AOP refactoring and code smells > Questions


 Question: Wouter


    Can you elaborate a bit on the main items that you think could be
    added to Java or aspectJ that will help the refactoring?

    Sure. Short answer: nothing.




                                 Center for Software Technology         Sander Mak
AOP refactoring and code smells > Questions


 Question: Wouter


    Can you elaborate a bit on the main items that you think could be
    added to Java or aspectJ that will help the refactoring?

    Sure. Short answer: nothing. Why?
           Refactorings per deļ¬nition depend on a language
           And aim to optimize usage of a language, e.g.:
                  goto considered harmful
                  switch is codesmell in presence of inheritance/polymorphism
           Certain refactorings can hint at language improvement though

    Changing a language could be seen as an ā€™ultimate refactoringā€™, and it
    would allow new refactorings


                                 Center for Software Technology                 Sander Mak
AOP refactoring and code smells > Questions


 Question: Gerbo




    The designers of Java had their reasons not to allow multiple
    (implementation) inheritance, but AspectJ opened some sort of back
    door by using (interfaces combined with) aspects for it. And the paper
    even recommends this usage (ā€œSplit abstract class into aspect and
    interfaceā€ and ā€œchange abstract class to interfaceā€), which possibly
    creates the ā€˜diamond problemā€™. So, what do we think of this - the
    original Java design ideas versus these abstract class code smells?




                                 Center for Software Technology       Sander Mak
AOP refactoring and code smells > Questions


 Question: Gerbo


       Question: Niels
    The designers of Java hadsmell just seems like a allow multiple
       The abstract class code their reasons not to solution for multiple
    (implementation)looks like another AspectJdescribe it is: ā€Whenever
       inheritance. It inheritance, but way to opened some sort of back
    door byextend (interfaces combined implementation you should use
       you using a class just for the with) aspects for it. And the paper
    even recommendsinter type declarations.ā€. Orclass intothis wrong?
       interfaces and this usage (ā€œSplit abstract do I see aspect and
    interfaceā€ and ā€œchange abstract class to interfaceā€), which possibly
    creates the ā€˜diamond problemā€™. So, what do we think of this - the
    original Java design ideas versus these abstract class code smells?




                                 Center for Software Technology      Sander Mak
AOP refactoring and code smells > Questions


 Question: Gerbo
                   Diamond problem



    The designers of Java had their reasons not to allow multiple
    (implementation) inheritance, but AspectJ opened some sort of back
    door by using (interfaces combined with) aspects for it. And the paper
    even recommends this usage (ā€œSplit abstract class into aspect and
    interfaceā€ and ā€œchange abstract class to interfaceā€), which possibly
    creates the ā€˜diamond problemā€™. So, what do we think of this - the
    original Java design ideas versus these abstract class code smells?




                                 Center for Software Technology       Sander Mak
AOP refactoring and code smells > Questions


 Question: Gerbo

    Common solution for diamond problem:
       Fix the ordering in which superclasses are consulted
                  Perl, Python
           Fully qualify calls to methods in superclasses
                  C++


    About the refactorings:

    Together, the pair eļ¬€ectively extracts a mixin from the original
    abstract class
    mixin: class that provides functionality to other classes, not created
    for stand-alone use


                                 Center for Software Technology          Sander Mak
AOP refactoring and code smells > Questions


 Question: Gerbo

    Now if we would want to create a diamond, we have to:


           have 2 interfaces
           each having a method in common
           inter-type declarations forcing these interfaces on a single class
           have 2 default implementations of this common method as
           inter-type addition




                                 Center for Software Technology                 Sander Mak
AOP refactoring and code smells > Questions


 Question: Gerbo

    Now if we would want to create a diamond, we have to:


           have 2 interfaces
           each having a method in common
           inter-type declarations forcing these interfaces on a single class
           have 2 default implementations of this common method as
           inter-type addition


    This last point will be ļ¬‚agged by ajc

    Conclusion: no multiple inheritance, rather: default implementations
    for interfaces.

                                 Center for Software Technology                 Sander Mak
AOP refactoring and code smells > Questions


 Question: Nabil

    Could you please elaborate more on when to use Extend Marker
    Interface with Signature? Because according to the authors it is used
    when you need to call a method that is speciļ¬c to a type implementing
    an interface that doesnā€™t declare the wanted method. However in the
    precondition the authors argue that this refactoring is only feasible if
    all types implementing the interface export the signature of the
    method we want to call. So if all types export the signature then the
    method we want to call is not speciļ¬c to a certain type, thus no
    refactoring is required. And if the types implementing the marker
    interface donā€™t export the signature and we have to enforce them to
    export the signature, then I would rather stick with downcast solution.
    But instead of doing it as illustrated in the paper, I would deļ¬ne
    another interface extending the marker interface and make it declare
    the speciļ¬c method and then make the speciļ¬c type implement the
    new interface.
                                 Center for Software Technology         Sander Mak
AOP refactoring and code smells > Questions


 Question: Nabil


                                                        public aspect AA {
 public class A {
                                                            interface Role{}
     public static void doA(){}                             interface Role2 extends Role{
                                                              public void speciļ¬cMethod();
 }                                                          }

 public class B {                                           declare parents: A implements Role;
                                                            declare parents: B implements Role2;
     public static void doB(){}
     public void speciļ¬cMethod(){}                          public void something(Role obj){
                                                              ((Role2) obj).speciļ¬cMethod();
 }                                                          }
                                                        }


                                 Center for Software Technology                                Sander Mak
AOP refactoring and code smells > Questions


 Question: Nabil


                                                        public aspect AA {
 public class A {
Solution in paper                     interface Role{}
Inter-type static void doA(){}
   public method introduction:        interface Role2 extends Role{
                                        public void speciļ¬cMethod();
 }                                    }
public abstract void Role.doSomething();

 public class B {                                           declare parents: A implements Role;
                                                            declare parents: B implements Role2;
     public static void doB(){}
     public void speciļ¬cMethod(){}                          public void something(Role obj){
                                                              ((Role2) obj).speciļ¬cMethod();
 }                                                          }
                                                        }


                                 Center for Software Technology                                Sander Mak
AOP refactoring and code smells > Questions


 Question: Nabil

    Comparing the solutions:
           Speciļ¬c type for downcast not necessary at compilation
           But Nabilā€™s solution solves this by inlining a second interface
           Drawback: all classes with marker interface must implement
           injected method
           Nabilā€™s solution avoids this
           .. paper calls its solution stopgap for a reason, they had a
           speciļ¬c scenario in mind


    In short: I like your solution better, though the original one ā€™tidies upā€™
    a bit more


                                 Center for Software Technology              Sander Mak
AOP refactoring and code smells > Questions


 Question: Niels


    The ā€Push downā€ refactoring rules are better (less code duplication) if
    the recommended action proposes another super-aspect which extends
    the previous super aspect (in cases where code duplication would
    occur) right?




                                 Center for Software Technology        Sander Mak
AOP refactoring and code smells > Questions


 Question: Niels


    The ā€Push downā€ refactoring rules are better (less code duplication) if
    the recommended action proposes another super-aspect which extends
    the previous super aspect (in cases where code duplication would
    occur) right?


    All I can say:
    Push down refactorings do not avoid code duplication, but try to get a
    more logical placement for concerns in the aspect hierarchy. It could
    even lead to code duplication!

    But Iā€™m not quite sure what you mean, could you explain a bit more?


                                 Center for Software Technology        Sander Mak
AOP refactoring and code smells > Questions


 Question: Jinfeng

    Suppose we have a pointcut call (public * *(..)), and it would match
    every public method call. And suppose we refactor a public method to
    a private method. (Then we might also need to modify the pointcut.
    So that would be a problem.) Can we detect and solve this problem
    when refactoring (to preserve the behavior)?




                                 Center for Software Technology      Sander Mak
AOP refactoring and code smells > Questions


 Question: Jinfeng

    Suppose we have a pointcut call (public * *(..)), and it would match
    every public method call. And suppose we refactor a public method to
    a private method. (Then we might also need to modify the pointcut.
    So that would be a problem.) Can we detect and solve this problem
    when refactoring (to preserve the behavior)?


    This is called the fragile pointcut problem, and is indeed a very
    important issue when refactoring OO code in the presence of AO code.

    Almost all ā€™traditionalā€™ (Fowler) refactorings can potentially break
    pointcuts.
    Wloka et al. created a tool that explicitly synchronizes (updates)
    pointcuts when refactoring, using a change impact analysis. Most tools
    ignore the issue it seems.
                                 Center for Software Technology       Sander Mak

More Related Content

What's hot

Develop skills in functional and non functional testing
Develop skills in functional and non functional testingDevelop skills in functional and non functional testing
Develop skills in functional and non functional testingMaveric Systems
Ā 
To document or not to document? An exploratory study on developers' motivatio...
To document or not to document? An exploratory study on developers' motivatio...To document or not to document? An exploratory study on developers' motivatio...
To document or not to document? An exploratory study on developers' motivatio...Hayim Makabee
Ā 
Agile software development
Agile software development Agile software development
Agile software development saurabh goel
Ā 
Extreme Programming
Extreme ProgrammingExtreme Programming
Extreme ProgrammingShankar Dahal
Ā 
The Extreme Programming (XP) Model
The Extreme Programming (XP) ModelThe Extreme Programming (XP) Model
The Extreme Programming (XP) ModelDamian T. Gordon
Ā 
Extreme Programming (XP)
Extreme Programming (XP)Extreme Programming (XP)
Extreme Programming (XP)dcsunu
Ā 
Aimtech Software Development Company Presentation
Aimtech Software Development Company PresentationAimtech Software Development Company Presentation
Aimtech Software Development Company PresentationAnahitYeprikyan2
Ā 
Introduction to Extreme Programming
Introduction to Extreme ProgrammingIntroduction to Extreme Programming
Introduction to Extreme ProgrammingNaresh Jain
Ā 
extreme programming
extreme programmingextreme programming
extreme programminghimanshumunjal
Ā 
eXtreme programming (XP) - An Overview
eXtreme programming (XP) - An OvervieweXtreme programming (XP) - An Overview
eXtreme programming (XP) - An OverviewGurtej Pal Singh
Ā 
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard WorkTaming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard WorkJoseph Yoder
Ā 
The Professional Software Engineer
The Professional Software EngineerThe Professional Software Engineer
The Professional Software EngineerEveryware Technologies
Ā 
Building an End-to-End Test Automation Pipeline for Conversational AI | Rasa ...
Building an End-to-End Test Automation Pipeline for Conversational AI | Rasa ...Building an End-to-End Test Automation Pipeline for Conversational AI | Rasa ...
Building an End-to-End Test Automation Pipeline for Conversational AI | Rasa ...Rasa Technologies
Ā 
Introduction of Software Engineering
Introduction of Software EngineeringIntroduction of Software Engineering
Introduction of Software EngineeringMuhammadTalha436
Ā 
Roles and responsibilities of an IT software professional
Roles and responsibilities of an IT software professionalRoles and responsibilities of an IT software professional
Roles and responsibilities of an IT software professionalannie annie
Ā 
Introduction To Software Engineering
Introduction To Software EngineeringIntroduction To Software Engineering
Introduction To Software EngineeringLeyla Bonilla
Ā 
Extreme programming
Extreme programmingExtreme programming
Extreme programmingMr SMAK
Ā 
XP Explained
XP ExplainedXP Explained
XP Explainedvineet
Ā 
SE_Lec 00_ Software Engineering 1
SE_Lec 00_ Software Engineering 1SE_Lec 00_ Software Engineering 1
SE_Lec 00_ Software Engineering 1Amr E. Mohamed
Ā 

What's hot (20)

Develop skills in functional and non functional testing
Develop skills in functional and non functional testingDevelop skills in functional and non functional testing
Develop skills in functional and non functional testing
Ā 
To document or not to document? An exploratory study on developers' motivatio...
To document or not to document? An exploratory study on developers' motivatio...To document or not to document? An exploratory study on developers' motivatio...
To document or not to document? An exploratory study on developers' motivatio...
Ā 
Agile software development
Agile software development Agile software development
Agile software development
Ā 
Extreme Programming
Extreme ProgrammingExtreme Programming
Extreme Programming
Ā 
The Extreme Programming (XP) Model
The Extreme Programming (XP) ModelThe Extreme Programming (XP) Model
The Extreme Programming (XP) Model
Ā 
Extreme Programming (XP)
Extreme Programming (XP)Extreme Programming (XP)
Extreme Programming (XP)
Ā 
Aimtech Software Development Company Presentation
Aimtech Software Development Company PresentationAimtech Software Development Company Presentation
Aimtech Software Development Company Presentation
Ā 
Introduction to Extreme Programming
Introduction to Extreme ProgrammingIntroduction to Extreme Programming
Introduction to Extreme Programming
Ā 
extreme programming
extreme programmingextreme programming
extreme programming
Ā 
eXtreme programming (XP) - An Overview
eXtreme programming (XP) - An OvervieweXtreme programming (XP) - An Overview
eXtreme programming (XP) - An Overview
Ā 
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard WorkTaming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Ā 
The Professional Software Engineer
The Professional Software EngineerThe Professional Software Engineer
The Professional Software Engineer
Ā 
Building an End-to-End Test Automation Pipeline for Conversational AI | Rasa ...
Building an End-to-End Test Automation Pipeline for Conversational AI | Rasa ...Building an End-to-End Test Automation Pipeline for Conversational AI | Rasa ...
Building an End-to-End Test Automation Pipeline for Conversational AI | Rasa ...
Ā 
Introduction of Software Engineering
Introduction of Software EngineeringIntroduction of Software Engineering
Introduction of Software Engineering
Ā 
Roles and responsibilities of an IT software professional
Roles and responsibilities of an IT software professionalRoles and responsibilities of an IT software professional
Roles and responsibilities of an IT software professional
Ā 
Introduction To Software Engineering
Introduction To Software EngineeringIntroduction To Software Engineering
Introduction To Software Engineering
Ā 
Extreme Programming ppt
Extreme Programming pptExtreme Programming ppt
Extreme Programming ppt
Ā 
Extreme programming
Extreme programmingExtreme programming
Extreme programming
Ā 
XP Explained
XP ExplainedXP Explained
XP Explained
Ā 
SE_Lec 00_ Software Engineering 1
SE_Lec 00_ Software Engineering 1SE_Lec 00_ Software Engineering 1
SE_Lec 00_ Software Engineering 1
Ā 

Similar to Codesmells for AspectJ

Refactoring
RefactoringRefactoring
RefactoringNaresh Jain
Ā 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Editionjexp
Ā 
WoMakersCode 2016 - Shit Happens
WoMakersCode 2016 -  Shit HappensWoMakersCode 2016 -  Shit Happens
WoMakersCode 2016 - Shit HappensJackson F. de A. Mafra
Ā 
Aspect oriented programming
Aspect oriented programmingAspect oriented programming
Aspect oriented programmingRobert MacLean
Ā 
Gene Based Software Refactoring Location Identification and Rectification For...
Gene Based Software Refactoring Location Identification and Rectification For...Gene Based Software Refactoring Location Identification and Rectification For...
Gene Based Software Refactoring Location Identification and Rectification For...IJCSIS Research Publications
Ā 
Iwsm2014 application of function points to software based on open source - ...
Iwsm2014   application of function points to software based on open source - ...Iwsm2014   application of function points to software based on open source - ...
Iwsm2014 application of function points to software based on open source - ...Nesma
Ā 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented ProgrammingAnumod Kumar
Ā 
Multi step automated refactoring for code smell
Multi step automated refactoring for code smellMulti step automated refactoring for code smell
Multi step automated refactoring for code smelleSAT Publishing House
Ā 
Multi step automated refactoring for code smell
Multi step automated refactoring for code smellMulti step automated refactoring for code smell
Multi step automated refactoring for code smelleSAT Journals
Ā 
Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problemharshit200793
Ā 
RESTful APIs and FRAPI
RESTful APIs and FRAPIRESTful APIs and FRAPI
RESTful APIs and FRAPIDavid Coallier
Ā 
International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)inventionjournals
Ā 
A preliminary study on using code smells to improve bug localization
A preliminary study on using code smells to improve bug localizationA preliminary study on using code smells to improve bug localization
A preliminary study on using code smells to improve bug localizationkrws
Ā 
Throwing Laravel into your Legacy Appā„¢
Throwing Laravel into your Legacy Appā„¢Throwing Laravel into your Legacy Appā„¢
Throwing Laravel into your Legacy Appā„¢Joe Ferguson
Ā 
IRJET- Voice to Code Editor using Speech Recognition
IRJET- Voice to Code Editor using Speech RecognitionIRJET- Voice to Code Editor using Speech Recognition
IRJET- Voice to Code Editor using Speech RecognitionIRJET Journal
Ā 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure rupeshchanchal
Ā 
The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)Stefan Koopmanschap
Ā 

Similar to Codesmells for AspectJ (20)

Quick Intro to Clean Coding
Quick Intro to Clean CodingQuick Intro to Clean Coding
Quick Intro to Clean Coding
Ā 
Refactoring
RefactoringRefactoring
Refactoring
Ā 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
Ā 
WoMakersCode 2016 - Shit Happens
WoMakersCode 2016 -  Shit HappensWoMakersCode 2016 -  Shit Happens
WoMakersCode 2016 - Shit Happens
Ā 
Aspect oriented programming
Aspect oriented programmingAspect oriented programming
Aspect oriented programming
Ā 
Gene Based Software Refactoring Location Identification and Rectification For...
Gene Based Software Refactoring Location Identification and Rectification For...Gene Based Software Refactoring Location Identification and Rectification For...
Gene Based Software Refactoring Location Identification and Rectification For...
Ā 
Iwsm2014 application of function points to software based on open source - ...
Iwsm2014   application of function points to software based on open source - ...Iwsm2014   application of function points to software based on open source - ...
Iwsm2014 application of function points to software based on open source - ...
Ā 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
Ā 
Multi step automated refactoring for code smell
Multi step automated refactoring for code smellMulti step automated refactoring for code smell
Multi step automated refactoring for code smell
Ā 
Multi step automated refactoring for code smell
Multi step automated refactoring for code smellMulti step automated refactoring for code smell
Multi step automated refactoring for code smell
Ā 
Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problem
Ā 
RESTful APIs and FRAPI
RESTful APIs and FRAPIRESTful APIs and FRAPI
RESTful APIs and FRAPI
Ā 
International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)
Ā 
A preliminary study on using code smells to improve bug localization
A preliminary study on using code smells to improve bug localizationA preliminary study on using code smells to improve bug localization
A preliminary study on using code smells to improve bug localization
Ā 
Throwing Laravel into your Legacy Appā„¢
Throwing Laravel into your Legacy Appā„¢Throwing Laravel into your Legacy Appā„¢
Throwing Laravel into your Legacy Appā„¢
Ā 
IRJET- Voice to Code Editor using Speech Recognition
IRJET- Voice to Code Editor using Speech RecognitionIRJET- Voice to Code Editor using Speech Recognition
IRJET- Voice to Code Editor using Speech Recognition
Ā 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
Ā 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
Ā 
Refactoring
RefactoringRefactoring
Refactoring
Ā 
The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)
Ā 

More from Sander Mak (@Sander_Mak)

Scalable Application Development @ Picnic
Scalable Application Development @ PicnicScalable Application Development @ Picnic
Scalable Application Development @ PicnicSander Mak (@Sander_Mak)
Ā 
Event-sourced architectures with Akka
Event-sourced architectures with AkkaEvent-sourced architectures with Akka
Event-sourced architectures with AkkaSander Mak (@Sander_Mak)
Ā 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painSander Mak (@Sander_Mak)
Ā 
The Ultimate Dependency Manager Shootout (QCon NY 2014)
The Ultimate Dependency Manager Shootout (QCon NY 2014)The Ultimate Dependency Manager Shootout (QCon NY 2014)
The Ultimate Dependency Manager Shootout (QCon NY 2014)Sander Mak (@Sander_Mak)
Ā 
Cross-Build Injection attacks: how safe is your Java build?
Cross-Build Injection attacks: how safe is your Java build?Cross-Build Injection attacks: how safe is your Java build?
Cross-Build Injection attacks: how safe is your Java build?Sander Mak (@Sander_Mak)
Ā 
Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)Sander Mak (@Sander_Mak)
Ā 

More from Sander Mak (@Sander_Mak) (20)

Scalable Application Development @ Picnic
Scalable Application Development @ PicnicScalable Application Development @ Picnic
Scalable Application Development @ Picnic
Ā 
Coding Your Way to Java 13
Coding Your Way to Java 13Coding Your Way to Java 13
Coding Your Way to Java 13
Ā 
Coding Your Way to Java 12
Coding Your Way to Java 12Coding Your Way to Java 12
Coding Your Way to Java 12
Ā 
Java Modularity: the Year After
Java Modularity: the Year AfterJava Modularity: the Year After
Java Modularity: the Year After
Ā 
Desiging for Modularity with Java 9
Desiging for Modularity with Java 9Desiging for Modularity with Java 9
Desiging for Modularity with Java 9
Ā 
Modules or microservices?
Modules or microservices?Modules or microservices?
Modules or microservices?
Ā 
Migrating to Java 9 Modules
Migrating to Java 9 ModulesMigrating to Java 9 Modules
Migrating to Java 9 Modules
Ā 
Java 9 Modularity in Action
Java 9 Modularity in ActionJava 9 Modularity in Action
Java 9 Modularity in Action
Ā 
Java modularity: life after Java 9
Java modularity: life after Java 9Java modularity: life after Java 9
Java modularity: life after Java 9
Ā 
Provisioning the IoT
Provisioning the IoTProvisioning the IoT
Provisioning the IoT
Ā 
Event-sourced architectures with Akka
Event-sourced architectures with AkkaEvent-sourced architectures with Akka
Event-sourced architectures with Akka
Ā 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
Ā 
The Ultimate Dependency Manager Shootout (QCon NY 2014)
The Ultimate Dependency Manager Shootout (QCon NY 2014)The Ultimate Dependency Manager Shootout (QCon NY 2014)
The Ultimate Dependency Manager Shootout (QCon NY 2014)
Ā 
Modular JavaScript
Modular JavaScriptModular JavaScript
Modular JavaScript
Ā 
Modularity in the Cloud
Modularity in the CloudModularity in the Cloud
Modularity in the Cloud
Ā 
Cross-Build Injection attacks: how safe is your Java build?
Cross-Build Injection attacks: how safe is your Java build?Cross-Build Injection attacks: how safe is your Java build?
Cross-Build Injection attacks: how safe is your Java build?
Ā 
Scala & Lift (JEEConf 2012)
Scala & Lift (JEEConf 2012)Scala & Lift (JEEConf 2012)
Scala & Lift (JEEConf 2012)
Ā 
Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)
Ā 
Akka (BeJUG)
Akka (BeJUG)Akka (BeJUG)
Akka (BeJUG)
Ā 
Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)
Ā 

Recently uploaded

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
Ā 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
Ā 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
Ā 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
Ā 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
Ā 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
Ā 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
Ā 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
Ā 
#StandardsGoals for 2024: Whatā€™s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: Whatā€™s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: Whatā€™s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: Whatā€™s new for BISAC - Tech Forum 2024BookNet Canada
Ā 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
Ā 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
Ā 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
Ā 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
Ā 
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | DelhiFULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhisoniya singh
Ā 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
Ā 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
Ā 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
Ā 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
Ā 
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
Ā 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
Ā 

Recently uploaded (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
Ā 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Ā 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
Ā 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
Ā 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
Ā 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Ā 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
Ā 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Ā 
#StandardsGoals for 2024: Whatā€™s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: Whatā€™s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: Whatā€™s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: Whatā€™s new for BISAC - Tech Forum 2024
Ā 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
Ā 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
Ā 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Ā 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Ā 
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | DelhiFULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
Ā 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Ā 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
Ā 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
Ā 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Ā 
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure service
Ā 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Ā 

Codesmells for AspectJ

  • 1. AOP refactoring and code smells Towards a Catalogue of Refactorings and Code Smells for AspectJ AOP Seminar - Session 15 Sander Mak Center for Software Technology, Universiteit Utrecht Januari 15, 2007 Center for Software Technology Sander Mak
  • 2. AOP refactoring and code smells Outline Introduction 1 AOP and refactoring 2 The paper 3 Other approaches 4 Conclusion 5 Questions 6 Center for Software Technology Sander Mak
  • 3. AOP refactoring and code smells > Introduction In the beginning Inļ¬‚uential book by Martin Fowler (1999) Preceded by PhD work of William Opdyke (1992) Many papers on OO refactoring followed Center for Software Technology Sander Mak
  • 4. AOP refactoring and code smells > Introduction Deļ¬ne refactoring What is refactoring? Subtitle of Fowlerā€™s book: improving design of existing code Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its internal structure. Martin Fowler Center for Software Technology Sander Mak
  • 5. AOP refactoring and code smells > Introduction Deļ¬ne refactoring What is refactoring? Subtitle of Fowlerā€™s book: improving design of existing code Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its internal structure. Martin Fowler Behavior preserving Structure changing Improving design Refactorings are small transformation steps for code Center for Software Technology Sander Mak
  • 6. AOP refactoring and code smells > Introduction Why refactor? Maintainable code More understandable code Compliance to standard practices Speeds up development Reusable code, separate structure from app. logic Pinpointing bugs becomes easier Essential ingredient of agile processes Source code is the main communication medium Center for Software Technology Sander Mak
  • 7. AOP refactoring and code smells > Introduction Why refactor? Maintainable code More understandable code Compliance to standard practices Speeds up development Reusable code, separate structure from app. logic Pinpointing bugs becomes easier Essential ingredient of agile processes Source code is the main communication medium XP Rule ā€Refactor Mercilesslyā€ Summarizing: to increase both quality and productivity of a developer Center for Software Technology Sander Mak
  • 8. AOP refactoring and code smells > Introduction When to refactor? Rule of Three If you do something similar 3 times in a row... refactor it! When adding new functionality ļ¬t it in elegantly by refactoring otherwise risk spaghetti-code... During code review Everytime you ļ¬nd a code smell Center for Software Technology Sander Mak
  • 9. AOP refactoring and code smells > Introduction Code smells A code smell is a heuristic that might indicate the need for refactoring. Examples: Feature envy a class is more concerned with other classesā€™ data than with its own Long parameter list pass enough parameters to let a method ļ¬nd what it needs, but nothing more Temporary ļ¬eld class member is used where local local scope would have been appropriate These have been published along with refactorings to cure the smells Center for Software Technology Sander Mak
  • 10. AOP refactoring and code smells > AOP and refactoring AOP and refactoring Observation: AOP and refactoring share a common high-level goal: Creating systems that are easier to understand and maintain Center for Software Technology Sander Mak
  • 11. AOP refactoring and code smells > AOP and refactoring AOP and refactoring Observation: AOP and refactoring share a common high-level goal: Creating systems that are easier to understand and maintain Simplicity - less errors Clarity - communicate intentions Brevity - conciseness over verbosity The cardinal rule of writing unmaintainable code is to specify each fact in as many places as possible and in as many ways as possible. - Roedy Green in: How to write unmaintainable code Center for Software Technology Sander Mak
  • 12. AOP refactoring and code smells > AOP and refactoring Refactoring extended AOP can take over where OO refactoring ends: Center for Software Technology Sander Mak
  • 13. AOP refactoring and code smells > AOP and refactoring Good style When there are several ways to solve a problem, how do we pick the right wayTM ? Follow intentions of language Languages dictate composition mechanisms Ideally: each concern separated, but you cannot separate what you cannot compose later Experience Follow good style rules E.g. as documented in catalogue Avoiding code smells Center for Software Technology Sander Mak
  • 14. AOP refactoring and code smells > The paper The paper Towards a catalogue of refactorings and code smells for AspectJ Based on PhD work of M. Monteiro, written with his supervisor J. Fernandes Premises of the paper: There is no notion of good AOP style yet 1 This can be improved by providing a catalogue of refactorings and 2 smells Toolsupport for integrating AOP with refactoring is lacking 3 Preservation of intention over preservation of behavior Center for Software Technology Sander Mak
  • 15. AOP refactoring and code smells > The paper The paper Three categories of refactorings: OO ā†’ AspectJ (10) 1 AspectJ internal refactorings (6) 2 part of OO refactorings can be ported to aspects other refactorings handle new concepts, e.g. pointcuts Inter-aspect refactorings (11) 3 Idea is to sequentially compose these refactorings. Fragile pointcut problem is not addressed explicitly Center for Software Technology Sander Mak
  • 16. AOP refactoring and code smells > The paper The paper What is not in the paper: Formalism for AOP refactoring Authors follow format introduced by Fowler: Typical situation, Recommended action, Motivation, Mechanics, Examples Tool support Neither for application .. .. nor detection Metrics Mentions related work for AOP complexity metrics though Center for Software Technology Sander Mak
  • 17. AOP refactoring and code smells > The paper Approach Empirical: take existing, appropriate codebases and experiment. Attempt 1 A workļ¬‚ow program was decomposed into use cases. Use cases were captured in AOP style. Four AOP refactorings could be described Invaluable experience was gained Monolithic aspect Aspect was not exemplary for AspectJ usage Conclusion: good OO style pre-condition for extracting aspects Center for Software Technology Sander Mak
  • 18. AOP refactoring and code smells > The paper Approach Empirical: take existing, appropriate codebases and experiment. Attempt 2 AOP design pattern implementations of Hanneman & Kiczales were studied. Goal: try to describe transformation of OO ā†’ AOP in terms of refactorings Great variety of diļ¬€erent aspects No domain knowledge necessary Some refactorings were too case speciļ¬c (this needs to be recognized) Center for Software Technology Sander Mak
  • 19. AOP refactoring and code smells > The paper Approach Considerations regarding this empirical approach: Result: realworld solutions to realworld problems It worked for OO, so why not for AOP Result may be skewed because of case selection E.g. exception handling was not considered Generality of ļ¬ndings is debatable Center for Software Technology Sander Mak
  • 20. AOP refactoring and code smells > The paper OO to AOP refactoring Replace implements with declare parents Problem: interface adds secondary role to a class Usually combined with inline interface with aspect Center for Software Technology Sander Mak
  • 21. AOP refactoring and code smells > The paper AOP internal refactoring Introduce aspect protection Problem: restrict usage of inter-type ļ¬eld to aspect and its sub-aspects Center for Software Technology Sander Mak
  • 22. AOP refactoring and code smells > The paper AOP internal refactoring Minor criticism: A bit of a hack Very speciļ¬c to AspectJ Center for Software Technology Sander Mak
  • 23. AOP refactoring and code smells > The paper AOP internal refactoring Minor criticism: A bit of a hack Very speciļ¬c to AspectJ In comparison, a refactoring like replace inter-type ļ¬eld with aspect map is much more general . Also, OO refactorings can be used in aspects (extract method, intra-method refactorings) Center for Software Technology Sander Mak
  • 24. AOP refactoring and code smells > The paper AOP internal refactoring Minor criticism: A bit of a hack Very speciļ¬c to AspectJ In Remark by Wouter comparison, a refactoring like replace inter-type ļ¬eld with aspect map the ā€Introducegeneral .Protectionā€ section, you might want to have In is much more Aspect some modiļ¬er that takes care of the protection? Also, OO refactorings canthis used in aspects (extract method, Sure, that would make be refactoring unnecessary intra-method refactorings) Center for Software Technology Sander Mak
  • 25. AOP refactoring and code smells > The paper AOP internal refactoring Minor criticism: A bit of a hack Remarkspeciļ¬c to AspectJ Very by Elmar Some of the refactorings like ā€Introduce Aspect Protectionā€ seem to thank their existance to (unclear, incomplete, faulty) semantics of In comparison, a refactoring like replace inter-type ļ¬eld with aspect AspectJ. Take for example the ā€Introduce Aspect Protectionā€ Canā€™t map is much more general . we argue that some of these semantics for AspectJ should change, instead of making a work around using refactoring? Also, OO refactorings can be used in aspects (extract method, Indeed. Still the existance of this refactoring in the catalogue intra-method refactorings) makes a programmer aware of the issues. Center for Software Technology Sander Mak
  • 26. AOP refactoring and code smells > The paper AOP internal refactoring Replace inter-type ļ¬eld with aspect map Problem: aspect introduces additional state to a class, but it might not need it all the time, so resources are wasted Inter-type declarations aļ¬€ect all instances of a class Inter-type declarations last a lifetime Center for Software Technology Sander Mak
  • 27. AOP refactoring and code smells > The paper AOP internal refactoring Replace inter-type ļ¬eld with aspect map Problem: aspect introduces additional state to a class, but it might not need it all the time, so resources are wasted Inter-type declarations aļ¬€ect all instances of a class Inter-type declarations last a lifetime Solution: Maintain mapping to additional data in aspect, re-route all ļ¬eld accesses to the aspect Highly similar to relationship aspects! This refactoring constitutes moving from static to dynamic relations. Center for Software Technology Sander Mak
  • 28. AOP refactoring and code smells > The paper AOP generalisation refactoring Goal of these refactorings: transform an application speciļ¬c aspect into a generalized, reusable aspect. Again, much of the OO idiom can be ported to aspects, with subtle diļ¬€erences: There is no inheritance/overriding between advice (as opposed to methods) Therefore it sometimes necessary to push down advice Weaving behavior might be surprising Center for Software Technology Sander Mak
  • 29. AOP refactoring and code smells > The paper AOP generalisation refactoring Pull up inter-type declaration Problem: inter-type declaration is better placed in a super aspect (not because of duplication!) Issues: Targets of inter-type declarations receive an instance of the declaration per aspect When refactoring identical inter-type ļ¬elds to super aspect, only one instance is created at weaving time Compare to making a ļ¬eld static With more than one sub aspect most likely not behavior preserving Center for Software Technology Sander Mak
  • 30. AOP refactoring and code smells > The paper AOP code smells Describe what code should not be like Smells can lead to speciļ¬c refactorings Smells are somewhat subjective Some of Fowlerā€™s smells hint at cross-cutting concerns Captured by ā€™extract feature into aspectā€™ refactoring This paper describes 3 smells Center for Software Technology Sander Mak
  • 31. AOP refactoring and code smells > The paper AOP code smells Smell 1: double personality Class has multiple roles Recall superimposed roles in design patterns Secondary role might be cross-cutting Smell 2: abstract classes Abstract classes need to be extended Preventing the extending class to inherit from other classes Default implementations can be provided by inter-type declarations Smell 3: aspect laziness Overuse of inter-type declarations Real AOP smell Center for Software Technology Sander Mak
  • 32. AOP refactoring and code smells > Other approaches Automation Catalogues are cool, but... All these smells and refactorings deal with concerns that are inherently scattered I think automation is essential to: Detect OO ā†’ AOP refactorings 1 Detect refactorings within aspects 2 Apply AOP refactorings 3 This sessionā€™s paper agrees, but does not contribute Center for Software Technology Sander Mak
  • 33. AOP refactoring and code smells > Other approaches AOP code smells Related work on code smells: Detecting bad smells in AspectJ Piveta et al. Describes 5 AOP smells Provides algorithm to ļ¬nd these A prototype implementation is available Contains a case study on three AspectJ systems Algorithms are not very sophisticated Center for Software Technology Sander Mak
  • 34. AOP refactoring and code smells > Other approaches AOP code smells Described smells and algorithms: Anonymous pointcut deļ¬nitions 1 Large aspects 2 Lazy aspects 3 Feature envy (deļ¬ned as: class containing pointcut) 4 Abstract method introduction 5 Implemented in plugin for AspectJ eclipse extension Center for Software Technology Sander Mak
  • 35. AOP refactoring and code smells > Other approaches AOP code smells Architecture plugin Described smells and algorithms: Anonymous pointcut deļ¬nitions 1 Large aspects 2 Lazy aspects 3 Feature envy (deļ¬ned as: class containing pointcut) 4 Abstract method introduction 5 Implemented in plugin for AspectJ eclipse extension Center for Software Technology Sander Mak
  • 36. AOP refactoring and code smells > Other approaches Anonymous pointcut detection Center for Software Technology Sander Mak
  • 37. AOP refactoring and code smells > Other approaches Anonymous pointcut detection In other words: all pointcuts containing AspectJ pointcut primitives Center for Software Technology Sander Mak
  • 38. AOP refactoring and code smells > Other approaches Abstract method introductions Abstract methods demand implementation, creates unnecessary coupling between aspect and class Center for Software Technology Sander Mak
  • 39. AOP refactoring and code smells > Other approaches Case study Programs analyzed: AspectJ examples Design pattern implementations Hannemann & Kiczales GlassBox inspector (J2EE monitoring app) Results: very little smells found, besides many anonymous pointcuts .. these are not necessary bad, most of them are used once Center for Software Technology Sander Mak
  • 40. AOP refactoring and code smells > Other approaches Case study Output analysis Programs analyzed: AspectJ examples Design pattern implementations Hannemann & Kiczales GlassBox inspector (J2EE monitoring app) Results: very little smells found, besides many anonymous pointcuts .. these are not necessary bad, most of them are used once Center for Software Technology Sander Mak
  • 41. AOP refactoring and code smells > Other approaches Smell metrics Mentioned in previous paper: Metrics based refactoring Simon et al. More formalized metrics, and graphical representation. Center for Software Technology Sander Mak
  • 42. AOP refactoring and code smells > Other approaches Smell metrics Mentioned in previous paper: Metrics based refactoring Simon et al. More formalized metrics, and graphical representation. Output analysis Not aspect oriented (yet) Center for Software Technology Sander Mak
  • 43. AOP refactoring and code smells > Other approaches Refactoring tool AspectJ Refactoring Tool (ART), Iwamoto et al. Works on PDGs, not on ASTs: Program Dependence Graph Existing formalism Like control ļ¬‚ow graph With additional information on data Automates application of refactorings Center for Software Technology Sander Mak
  • 44. AOP refactoring and code smells > Other approaches Refactoring tool 24 refactorings are proposed: OO ā†’ AOP refactorings internal AOP refactorings there is ample overlap with session paper Diļ¬€erence: refactorings are composed with laws Center for Software Technology Sander Mak
  • 45. AOP refactoring and code smells > Other approaches Refactoring tool Example law, move ļ¬eld to aspect: 24 refactorings are proposed: OO ā†’ AOP refactorings internal AOP refactorings there is ample overlap with session paper Diļ¬€erence: refactorings are composed with laws Center for Software Technology Sander Mak
  • 46. AOP refactoring and code smells > Other approaches Aspect Mining So far weā€™ve seen tools to: Find code smells Find OO refactorings Apply refactorings In order to ļ¬nd OO ā†’ AOP refactorings, we need something like aspect mining. Center for Software Technology Sander Mak
  • 47. AOP refactoring and code smells > Other approaches Aspect Mining So far weā€™ve seen tools to: Find code smells Question: Rinse Refactoring refactorings Find OO code into aspects can become a little tedious when trying to Apply refactorings track down all classes involved in say a observer pattern. There is research being done in aspect mining techniques [1] do you think with In the proposed catalogue of refactorings and code smells for AspectJ and order to ļ¬nd OO ā†’ AOP refactorings, we need something like aspect mining.mining techniques we could come anything close to the these aspect current support for refactorings in IDEs for normal OO concerns? [1]: Applying and combining three diļ¬€erent aspect Mining Techniques Center for Software Technology Sander Mak
  • 48. AOP refactoring and code smells > Other approaches Aspect Mining Approach created at TU Delft, combines and compares three aspect mining techniques: Fan-in analysis 1 Identiļ¬er analysis 2 Dynamic analysis 3 Each of these is tested on JHotDraw, a graphics application created to showcase good usage of design patterns. Center for Software Technology Sander Mak
  • 49. AOP refactoring and code smells > Other approaches Aspect Mining Fan-in analysis Count number of locations from which control is passed into a module In OO: fan-in for method M is number of distinct bodies that can call M Idea: if a method is called from many places, it is probably cross-cutting Certain treshold needs to be in place (experimentally determined value: 10) Analysis excludes getter/setters and utility methods like toString() Center for Software Technology Sander Mak
  • 50. AOP refactoring and code smells > Other approaches Aspect Mining Identiļ¬er analysis Lexical analysis of identiļ¬ers in code Split composed name into single words Take stem of words Group common words If a group is scattered over multiple classes/methods: it is probably a cross-cutting concern Depends on naming conventions Center for Software Technology Sander Mak
  • 51. AOP refactoring and code smells > Other approaches Aspect Mining Dynamic analysis Analyse execution traces of (instrumented) program Run program with diļ¬€erent scenarios (use cases) Keep track of locality in code (call stack) Analyse which methods relate to which use case and which are generic Depends on well-chosen scenarios Center for Software Technology Sander Mak
  • 52. AOP refactoring and code smells > Other approaches Aspect Mining A framework was devised to test all analyses. Some concerns as detected: Contract enforcement (pre-condition checking) Undo Observer pattern Persistance (read/write functionality) All three techniques found the most common concerns. Fan-in was found to be suitable for larger applications, and the techniques were complementary for uncommon concerns. No production quality tool was implemented. Center for Software Technology Sander Mak
  • 53. AOP refactoring and code smells > Other approaches Other tools/methods Rolebased Refactoring Hannemann & Kiczales Programmer maps conceptual concerns to code fragments. Tools helps with mapping, and with manipulating the code fragments. Aspect mining tool Lexical analysis and type based analysis, with stand alone visualizer. Based on modiļ¬ed ajc FEAT/ConcernMapper Eclipse plugin to navigate/analyze/refactor AspectJ code. Concern Manipulation Eclipse plugin (originally by IBM) to manage Environment and build concerns in code. No analysis. Center for Software Technology Sander Mak
  • 54. AOP refactoring and code smells > Conclusion Concluding remarks The paper gives a thorough description of a catalogue Unfortunately, it does not consider much more Especially more could be said on toolsupport Moving refactoring from OO to AOP brings in a lot of subtleties (aspects vs. classes) AOP refactoring research ļ¬eld is fairly new and open There are many (research)tools, but Its not very clear how these all relate and how powerful they are To answer Rinseā€™s question: I donā€™t think it comes near legacy refactoring support yet Center for Software Technology Sander Mak
  • 55. AOP refactoring and code smells > Conclusion Concluding remarks The paper gives a thorough description of a catalogue Unfortunately, it does not consider much more Especially more could be said on toolsupport Masterā€™s thesis Moving refactoring from OO to AOP brings in a lot of subtleties May be someone should take on this challenge and survey the (aspects vs. classes) AOP refactoring tools ļ¬eld and create the ultimate formalism and tool for refactoring research ļ¬eld is fairly new and open AOP AOP refactoring :-) ? There are many (research)tools, but Its not very clear how these all relate and how powerful they are To answer Rinseā€™s question: I donā€™t think it comes near legacy refactoring support yet Center for Software Technology Sander Mak
  • 56. AOP refactoring and code smells > Questions Question: Wouter I think that some of the problems could be solved better with some Java and/or AspectJ changes, for example: In section 4.2 ā€generalize target typeā€ refactoring is used: private interface NewTypeClass {} declare parents: SomeClass implements NewTypeClass; This makes the code better by deļ¬ning a role/type that the class then ā€™implementsā€™. But the Interface/implements constructs of Java arenā€™t really designed for modeling roles right? I think that there might be a need for some stronger or better typing system than this (maybe something like Haskellā€™s?). Center for Software Technology Sander Mak
  • 57. AOP refactoring and code smells > Questions Question: Wouter I think that some of the problems could be solved better with some Java and/or AspectJ changes, for example: In section 4.2 ā€generalize target typeā€ refactoring is used: private interface NewTypeClass {} declare parents: SomeClass implements NewTypeClass; This makes the code better by deļ¬ning a role/type that the class then ā€™implementsā€™. But the Interface/implements constructs of Java arenā€™t really designed for modeling roles right? I think that there might be a need for some stronger or better typing system than this (maybe something like Haskellā€™s?). Letā€™s discuss Center for Software Technology Sander Mak
  • 58. AOP refactoring and code smells > Questions Question: Wouter Can you elaborate a bit on the main items that you think could be added to Java or aspectJ that will help the refactoring? Center for Software Technology Sander Mak
  • 59. AOP refactoring and code smells > Questions Question: Wouter Can you elaborate a bit on the main items that you think could be added to Java or aspectJ that will help the refactoring? Sure. Short answer: nothing. Center for Software Technology Sander Mak
  • 60. AOP refactoring and code smells > Questions Question: Wouter Can you elaborate a bit on the main items that you think could be added to Java or aspectJ that will help the refactoring? Sure. Short answer: nothing. Why? Refactorings per deļ¬nition depend on a language And aim to optimize usage of a language, e.g.: goto considered harmful switch is codesmell in presence of inheritance/polymorphism Certain refactorings can hint at language improvement though Changing a language could be seen as an ā€™ultimate refactoringā€™, and it would allow new refactorings Center for Software Technology Sander Mak
  • 61. AOP refactoring and code smells > Questions Question: Gerbo The designers of Java had their reasons not to allow multiple (implementation) inheritance, but AspectJ opened some sort of back door by using (interfaces combined with) aspects for it. And the paper even recommends this usage (ā€œSplit abstract class into aspect and interfaceā€ and ā€œchange abstract class to interfaceā€), which possibly creates the ā€˜diamond problemā€™. So, what do we think of this - the original Java design ideas versus these abstract class code smells? Center for Software Technology Sander Mak
  • 62. AOP refactoring and code smells > Questions Question: Gerbo Question: Niels The designers of Java hadsmell just seems like a allow multiple The abstract class code their reasons not to solution for multiple (implementation)looks like another AspectJdescribe it is: ā€Whenever inheritance. It inheritance, but way to opened some sort of back door byextend (interfaces combined implementation you should use you using a class just for the with) aspects for it. And the paper even recommendsinter type declarations.ā€. Orclass intothis wrong? interfaces and this usage (ā€œSplit abstract do I see aspect and interfaceā€ and ā€œchange abstract class to interfaceā€), which possibly creates the ā€˜diamond problemā€™. So, what do we think of this - the original Java design ideas versus these abstract class code smells? Center for Software Technology Sander Mak
  • 63. AOP refactoring and code smells > Questions Question: Gerbo Diamond problem The designers of Java had their reasons not to allow multiple (implementation) inheritance, but AspectJ opened some sort of back door by using (interfaces combined with) aspects for it. And the paper even recommends this usage (ā€œSplit abstract class into aspect and interfaceā€ and ā€œchange abstract class to interfaceā€), which possibly creates the ā€˜diamond problemā€™. So, what do we think of this - the original Java design ideas versus these abstract class code smells? Center for Software Technology Sander Mak
  • 64. AOP refactoring and code smells > Questions Question: Gerbo Common solution for diamond problem: Fix the ordering in which superclasses are consulted Perl, Python Fully qualify calls to methods in superclasses C++ About the refactorings: Together, the pair eļ¬€ectively extracts a mixin from the original abstract class mixin: class that provides functionality to other classes, not created for stand-alone use Center for Software Technology Sander Mak
  • 65. AOP refactoring and code smells > Questions Question: Gerbo Now if we would want to create a diamond, we have to: have 2 interfaces each having a method in common inter-type declarations forcing these interfaces on a single class have 2 default implementations of this common method as inter-type addition Center for Software Technology Sander Mak
  • 66. AOP refactoring and code smells > Questions Question: Gerbo Now if we would want to create a diamond, we have to: have 2 interfaces each having a method in common inter-type declarations forcing these interfaces on a single class have 2 default implementations of this common method as inter-type addition This last point will be ļ¬‚agged by ajc Conclusion: no multiple inheritance, rather: default implementations for interfaces. Center for Software Technology Sander Mak
  • 67. AOP refactoring and code smells > Questions Question: Nabil Could you please elaborate more on when to use Extend Marker Interface with Signature? Because according to the authors it is used when you need to call a method that is speciļ¬c to a type implementing an interface that doesnā€™t declare the wanted method. However in the precondition the authors argue that this refactoring is only feasible if all types implementing the interface export the signature of the method we want to call. So if all types export the signature then the method we want to call is not speciļ¬c to a certain type, thus no refactoring is required. And if the types implementing the marker interface donā€™t export the signature and we have to enforce them to export the signature, then I would rather stick with downcast solution. But instead of doing it as illustrated in the paper, I would deļ¬ne another interface extending the marker interface and make it declare the speciļ¬c method and then make the speciļ¬c type implement the new interface. Center for Software Technology Sander Mak
  • 68. AOP refactoring and code smells > Questions Question: Nabil public aspect AA { public class A { interface Role{} public static void doA(){} interface Role2 extends Role{ public void speciļ¬cMethod(); } } public class B { declare parents: A implements Role; declare parents: B implements Role2; public static void doB(){} public void speciļ¬cMethod(){} public void something(Role obj){ ((Role2) obj).speciļ¬cMethod(); } } } Center for Software Technology Sander Mak
  • 69. AOP refactoring and code smells > Questions Question: Nabil public aspect AA { public class A { Solution in paper interface Role{} Inter-type static void doA(){} public method introduction: interface Role2 extends Role{ public void speciļ¬cMethod(); } } public abstract void Role.doSomething(); public class B { declare parents: A implements Role; declare parents: B implements Role2; public static void doB(){} public void speciļ¬cMethod(){} public void something(Role obj){ ((Role2) obj).speciļ¬cMethod(); } } } Center for Software Technology Sander Mak
  • 70. AOP refactoring and code smells > Questions Question: Nabil Comparing the solutions: Speciļ¬c type for downcast not necessary at compilation But Nabilā€™s solution solves this by inlining a second interface Drawback: all classes with marker interface must implement injected method Nabilā€™s solution avoids this .. paper calls its solution stopgap for a reason, they had a speciļ¬c scenario in mind In short: I like your solution better, though the original one ā€™tidies upā€™ a bit more Center for Software Technology Sander Mak
  • 71. AOP refactoring and code smells > Questions Question: Niels The ā€Push downā€ refactoring rules are better (less code duplication) if the recommended action proposes another super-aspect which extends the previous super aspect (in cases where code duplication would occur) right? Center for Software Technology Sander Mak
  • 72. AOP refactoring and code smells > Questions Question: Niels The ā€Push downā€ refactoring rules are better (less code duplication) if the recommended action proposes another super-aspect which extends the previous super aspect (in cases where code duplication would occur) right? All I can say: Push down refactorings do not avoid code duplication, but try to get a more logical placement for concerns in the aspect hierarchy. It could even lead to code duplication! But Iā€™m not quite sure what you mean, could you explain a bit more? Center for Software Technology Sander Mak
  • 73. AOP refactoring and code smells > Questions Question: Jinfeng Suppose we have a pointcut call (public * *(..)), and it would match every public method call. And suppose we refactor a public method to a private method. (Then we might also need to modify the pointcut. So that would be a problem.) Can we detect and solve this problem when refactoring (to preserve the behavior)? Center for Software Technology Sander Mak
  • 74. AOP refactoring and code smells > Questions Question: Jinfeng Suppose we have a pointcut call (public * *(..)), and it would match every public method call. And suppose we refactor a public method to a private method. (Then we might also need to modify the pointcut. So that would be a problem.) Can we detect and solve this problem when refactoring (to preserve the behavior)? This is called the fragile pointcut problem, and is indeed a very important issue when refactoring OO code in the presence of AO code. Almost all ā€™traditionalā€™ (Fowler) refactorings can potentially break pointcuts. Wloka et al. created a tool that explicitly synchronizes (updates) pointcuts when refactoring, using a change impact analysis. Most tools ignore the issue it seems. Center for Software Technology Sander Mak