Investigating the incidence of code smells in methods of design patterns
Design Patterns, Code Smells, Software Design, Software Repository Mining
Design patterns are reusable solutions that can be applied to solve specific problems of software projects. However, developers may not implement patterns adequately on some occasions. This can lead to the appearance of code smells. Code smells (or smells) are fragments of code that can indicate potential design flaws. Co-occurrences are situations in which design patterns and smells exist simultaneously in the same code unit (e.g., classes and methods of Java-based software projects). In case of such phenomenon occurs frequently it can reveal opportunities to investigate if a bad practice in the application of patterns is the cause of the occurrence of smells. As a consequence, refining the way how developers apply design patterns may be a good measure to avoid code smells. In this context, we present two experimental studies that aim at examining cases of co-occurrence of patterns and smells. Both studies required the application of detection tools to evaluate Java-based software projects. With our first study, we seek to comprehend the frequency by which code smells co-occur with design patterns. We also report the most common cases of co-occurrence. To achieve this, we identified instances of smells in methods of design patterns of 25 software systems. We also manually inspected source code fragments to obtain useful information about pairs of patterns and smells. Among other findings, we perceived that methods that take part in the implementation of the Adapter pattern are prone to contain smells, e.g., the Feature Envy smell, although it can be argued that the detection of this smell in this context is a false positive. Our second study has the purpose of analyzing the evolution of open-source software projects. We wanted to provide insights about the co-occurrences along with the evolution of the projects. As a result, we found out that the Template Method pattern is more inclined to appear concomitantly with smells through time.