从源码中抽取设计模式对于提高软件可理解性和可维护性、软件设计重用以及软件重构具有重要意义。面向Java语言提出了一种静态和动态分析相结合的源码中设计模式的抽取方法。具体地,研究了源码中设计模式抽取的静态结构分析过程,为了进一步提高设计模式实例抽取的准确率,对结构分析得到的创建型模式候选,使用创建对象的多重性分析方法进行验证,对结构分析得到的行为型模式候选,使用动态分析的方法进行验证,以区分结构相似但行为不同的模式的实例。最后实现了设计模式抽取工具并对开源软件中的模式实例进行抽取。通过实验数据,验证了设计模式实例抽取及验证方法的可行性及有效性。
Identifying design patterns from source code is one of the most promising methods for improving software maintainability,reusing experience and facilitating software refactoring.This paper presented an approach that combined static and dynamic analysis on detecting design patterns from Java source code and illustrated the static structural analysis phase of identi-fying pattern candidates.Especially,to improve the detecting precision,the approach executed multiplicity analysis of object creation to validate creational pattern candidates and dynamic analysis to validate behavior pattern candidates.After the validation of behavior candidates,the approach distinguished those instances belonged to patterns which had similar structures but different behaviors successfully.Finally,this paper implemented a tool of extracting design pattern from Java source code.The experiment results of applying it on an open source software show the feasibility and availability of the approach.