| Design patterns detection is an important task in understanding and maintaining software system,it's not only conducive to recovery and discovery of software architecture,but also an important foundation for evaluating the quality of software.At present,the design patterns detection still exists some questions: 1)the detection effect of variants of design patterns is not good enough.2)it's hard to distinguish patterns which have same structures and different intentions.3)the detection of behavioral design patterns is complicated.4)the problem of combinatorial explosion is still outstanding.The aim of this paper is to identify variants of design patterns efficiently and improve the accuracy of design patterns detection.An approach of design patterns detection based on stacked generalization is proposed in combination with object-oriented software metrics and pattern microstructures.The approach uses some typical machine learning algorithms to train a metric classifier and a microstructure classifier for each design pattern,then a stacked classifier is constructed and further trained on the predictive values of the two classifiers and some related object modeling features.These classifiers are used to classify a candidate pattern instance,thus predicting whether the candidate pattern instance is true or not.Before the classifiers are trained,this paper firstly collects positive and negative pattern instances,and then calculates candidate metric features and microstructure features for every instance as more as possible,thus generating data sets for relevant classifiers.Then some typical feature selection algorithms are applied to the candidate metric features and microstructure features firstly,and the classifiers are trained by traversing some typical supervised learning algorithms.Finally,we found the appropriate metric feature set,metric classifier,microstructure feature set,microstructure classifier and stacked classifier for each of the five design patterns of the experiments.This paper also analyzes and summarizes the problems encountered in design patterns detection,namely combinatorial explosion and pattern variants.Design pattern microstructure and related basic concepts and principles are defined.The existing design patterns microstructures are divided into two categories,namely method microstructures and non-method microstructures,at the same time,we proposed five new method microstructures according to the need of design patterns detection.And an idea of mapping design patterns' methods is given by using the bit vector representations of method microstructures,which compensates for the lack of existing design patterns detection methods which are based on machine learning.For the detection of behavioral design patterns,this paper proposes to describe the behavior characteristics of patterns from the perspective of microstructures which can reduce the complexity of the detection of behavioral design patterns.An approach of using the necessary microstructures of design patterns is proposed to solve the problem of combinatorial explosion encountered in design patterns detection.To evaluate the proposed approach,we developed a prototype tool and made experiments on several classic open source projects,such as JUnit.At the same time,we compared the proposed approach with two existing tools,it's proved that the proposed approach can largely solve the combinatorial explosion problem and improve the accuracy of design patterns detection and recall rate.In particular,for the observer design pattern,the proposed method is more effective than the method which is based on similarity scoring of structures. |