Relaxing queries to detect variants of design patterns

Patrycja Wȩgrzynowicz, Krzysztof Stencel · 2013

Design patterns codify general solutions to frequently encountered design problems. They also facilitate writing robust and readable code. Their usage happens to be particularly profitable if the documentation of the resulting system is lost, inaccurate or out of date. In reverse engineering, detection of instances of design patterns is extremely helpful as it aids grasping high level design ideas. However, the actual instances of design patterns can diverge from their canonical textbook templates. Useful pattern detection tools should thus be able to identify not only orthodox implementations but also their disparate variants. In this paper, we present a method to generate queries to detect canonical instances of design patters. We formulate these queries so that they are language-agnostic. They precisely reflect the intents of the canonical implementations of design patterns. However, they abstract from any peculiarities of programming languages. Next, we show a systematic technique to relax these queries so that they also cover variant implementations of patterns. We discuss our proof-of-concept implementation of this approach in our prototype tool D-CUBED. Finally, we report the results of an experimental comparison of D-CUBED and state-of-the-art detectors.

Read the paper · More papers on PaperTik