Design Pattern Detection by Template Matching
To detect a design pattern from a software system, a template matching method is used, where we identify exact matches of pattern instances from source code and also its possible variants. The problem of design pattern detection is reduced into a problem of matrix matching. Hence this method encodes both pattern and system knowledge into overall matrixes to calculate similarity score by normalized cross correlation. Normalized cross correlation (CCn) calculate the degree of similarity between a design pattern and the part of a system given by the formulaCCn = ∑f(x) • g(x) / |f(x)| •|g(x)|
It defines the cosθ value, where θ is the angle between vector f and g. The maximum value is 1 when f and g is an exact match, i.e., θ= 0. While detecting a pattern we actually search for unique set of design features of the pattern from sour e code. We create an n × n matrix for the generalization relationship, where n is the number of classes. If the ith and jth classes have the generalization relationship, the corresponding cell of the matrix is set to 1. Otherwise, it is set to 0. This approach also avoid the false positives caused by individual matches. However, there will be minor effect on this approach by adding new feature matrixes. The approach encodes eight design features but these design features are not complete.
Detection of Design Pattern Using Graph Isomorphism and Normalized Cross Correlation
Paper presents an approach for design pattern detection with the help of Graph Isomorphism and Normalized Cross Correlation techniques. In this approach, both the system UML class diagram and design pattern class diagrams are converted into directed graphs. The nodes of the graph act as classes whereas the edges connecting the nodes refers to the relationship among the corresponding classes. If any two classes are connected, having more than one relationship, then the relationship weight becomes the multiplication of the individual weights corresponding to the relationship. First of all we generate XML files from source code using eclipse from where we collect information of system graph and pattern graph which help to identify Contribution Value of Class in both SG and PG. Then we extract system subgraph and pattern graph on which further normalized cross correlation is performed which helps to examine percentage matching occurrences. The Graph Isomorphism technique is useful to detect design patterns in order to enhance usability and reliability of the proposed technique.
Design Pattern Detection Using Similarity Scoring
Design pattern detection with similarity score technique employ a similarity algorithm graph, whose input is both the system graph and the pattern graph, then calculates similarity scores between their vertices. The major benefit of this methodology is detection of modified version of design pattern. The system is partitioned to clusters of hierarchies to overcome efficiency problem due to exploration space, so that the algorithm can be applied to subsystems rather than to the whole system. In methodology all kinds of generalization relationships are identified for building the hierarchies of inheritance. Then we construct subsystem matrices as subsystem consist on classes belonging to one or more hierarchies. Normalized similarity scores by similarity algorithm between each pattern role and each subsystem class are calculated. To seek extraction of pattern, as instance of each pattern is present in each subsystem which means that each pattern role is associated with one class. The selection of the highest score for each role is based on the observation that a class assigned a score that is less than the score of another class definitely satisfies fewer criteria according to the sought pattern description. As a result, the class with the lower score is a worse candidate for the specific pattern role. To solve the efficiency problem, irrelevant subsystems should exclude and the roles with the most unique characteristics should be preferred. In shortcomings of the system few of the targeted patterns were missed i.e. false negatives, with no false positives in the application of this methodology.