|
ConcernMorph: Metrics-based Detection of Crosscutting PatternsEduardo Figueiredo, Jon Whittle, and Alessandro Garcia
AbstractCrosscutting concerns can hinder maintainability of a design because they do not adhere to a system’s underlying modular structure. Developers, therefore, may wish to refactor designs to improve modularisation or to implement crosscutting concerns as aspects. However, few tools currently exist that assist developers in detecting crosscutting concerns in their code. Furthermore, we are not aware of any tools that classify crosscutting concerns once they are found. Classification is important because, as recent studies have shown, crosscutting concerns are not always harmful. This paper describes a tool, ConcernMorph, for identifying crosscutting concerns and classifying them into one of a number of predefined crosscutting patterns. |
||||||||||
|
ConcernMorph - Detecting Crosscutting Patterns - Credits |
||||||||||
|
Detecting Crosscutting PatternsThis supplementary text presents a heuristic detection strategy to automate the process of identifying those crosscutting patterns. Thi approach is supported by ConcernMorph. The proposed detection strategy technique combines information from a complementary set of concern analysis techniques including concern-oriented [3, 4] and conventional metrics [2, 8], concern-based clone detection [1], and concern-based dependency between components [4]. We summarise below which techniques have been considered to identify each category of crosscutting patterns. |
||||||||||
|
Concern-oriented metrics to identify flat crosscutting shapesInspired by detection strategies proposed by Marinescu [9], we define specific strategies to identify concerns with flat crosscutting shapes. Marinescu’s work uses conventional module-driven metrics aiming at detecting a set of traditional flaws, such as the Shotgun Surgery bad smell [5]. Here, the detection strategy mechanism is extended with recently proposed concern metrics [3, 4]. We present below a short description for six concern and conventional metrics used by the elaborated detection strategies. More information about those metrics can be found at the respective references.
Concern-oriented metrics
Conventional size metrics
Before presenting the three detection strategies aiming at identifying Black Sheep, Octopus, and God Concern, we also define two conditions A (Little Dedication) and B (High Dedication) used by the rules. We explicitly separate those two conditions from the strategies in order to reuse them in more than one detection strategy and also make the rules easier to understand.
Little Dedication
High Dedication
The first rule (R01) below identifies an instance of the Black Sheep crosscutting pattern if all components which have this concern dedicate only a few percentage points of attributes and operations to it (less than 33 %). In other words, it the condition A (Little Dedication) holds.
Black Sheep
The next rule (R02) verifies if a crosscutting concern not classified as Black Sheep is an Octopus candidate. According to this detection strategy, this crosscutting pattern occurs if every component realising parts of the concern has either little dedication (condition A) or high dedication (condition B) to it. Besides, at least one component have to be little dedicated to the concern (octopus’ tentacles) and at least one component has to be highly dedicated (octopus’ body). We define a component as highly dedicated to a concern when the percentage of attributes and operations are equal to or higher than 67 %.
Octopus
Finally, the third detection strategy (R03) aims at finding God Concern. It warns the developer of a God Concern candidate if two conditions are satisfied: (i) if the given concern affects more than 33% of the system’s components and (ii) if most of those affected - not all - components are highly dedicated to that concern (condition B).
God Concern
|
||||||||||
|
Tree-based algorithms to detect inheritance-wise concernsBoth Climbing Plant and Hereditary Disease crosscutting patterns are straightforwardly identified. Basically, we need two steps to spot them: (1) create a forest (i.e., a disjoint union of trees) including all inheritance trees which have at least one component realising the concern under consideration; and (2) verify which trees in the forest have at least one vertex not assigned to the concern, although every root must realise the given concern. Once those two steps are accomplished, trees with all vertices realising the concern are regarded to Climbing Plant. On the other hand, Hereditary Disease is identified by trees with at least one vertex not assigned to the concern. |
||||||||||
|
Graph search algorithms to find communicative concernsThe first step to identify the communicative concerns, Tree Root, Tsunami, Neural Network, and King Snake, is to build for each concern under analysis a graph of connections, called graph of concern dependencies. The vertices of this graph are all components realising the analysed concern and the edges are coupling connections between a pair of components which are related to the concern. For example, The figure below presents the graph of concern dependencies for an implementation [6] of the Observer pattern. This figure also shows a partial code of the Point class in order to illustrate the two edges that connect this vertex to Subject and Observer. In other words, the shadowed areas of the Point class refer to the Subject and Observer interfaces what results in the two edges leaving the Point vertex.
After the creation of those graphs for each concern, our heuristic strategy to identify crosscutting patterns use variations of graph search algorithms, such as Breadth First Search (BFS) and Depth First Search (DFS) [7]. Tree Root and Tsunami can be found by an adapted BFS algorithm. Our BFS variant records the number of vertices that can be reached by each vertex. The figure below illustrates a simulation of this BFS algorithm in the sample graph of the above figure. The number of vertices reached by a given vertex is placed between brackets when a vertex becomes black (visited). Once the BFS execution has finished, the wave source of Tsunami is the vertex with the highest assigned value. Tree Root is identified using the same algorithm, but a graph with inverted edges is used as input. In the Tree Root case, the highest vertex value indicates a trunk.
Furthermore, the Neural Network and King Snake crosscutting patterns are detected by using graph algorithms in directed acyclic graph (DAG), i.e., a directed graph with no directed cycles. We implemented a DFS algorithm [7] that marks vertices it has already visited and does not visit them again. Hence, it transforms the graph of concern dependencies into a DAG. The resulting DAG includes all components participating in the Neural Network crosscutting pattern. To identify King Snake though, we need a step further. Our DFS variant marks the vertex with the longest path (deepest) from another arbitrary vertex. Therefore, we retrieve components in the longest path between two nodes and take them as composing the King Snake crosscutting pattern. |
||||||||||
|
Clone detection techniques and structural analysis to identify other abusive concernsCopy Cat and Dolly Sheep require the use of clone detection techniques [1] to find duplicated or similar pieces of concern code in different components. In fact, however, we have not yet implemented an algorithm to automate their detection. The other two crosscutting patterns, Data Concern and Behavioural Concern, are identified based on structural analysis of components realising the target concern. The heuristic strategy is, for every component, to investigate all members realising the concern. Then, a concern whose composing components have only attributes, class variable, or getting and setting methods to realise it is classified as Data Concern. Similarly, a concern which is composed of only methods and constructors (and advice in case of AspectJ programs) is considered Behavioural Concern. Concern-oriented metrics, such as NOCA and NOCO (presented above), can also be used to support the identification of Data Concern and Behavioural Concern. However, we cannot rely only on those metrics since they do not make any distinction between getting and setting methods from other ordinary operations. |
||||||||||
|
References
|