Customizable Feature-Based Design Pattern Recognition: Integrating Multiple Techniques

Introduction to Design Patterns and Motivation

  • Definition of Design Patterns: A design pattern offers guidelines on when, how, and why an implementation can be created to solve a general problem in a particular context ([GoF]).
  • Application Areas: Design patterns are applied across software architectures, interfaces, security, and services.
  • Productivity Gains: The application of design patterns can lead to a productivity increase of 25%40%25\%-40\%.
  • Need for Design Pattern Recovery: Recovery is essential for software maintenance, re-documentation, reverse engineering, and reengineering.

Challenges in Design Pattern Detection

  • Accuracy Variation and Challenges: Detecting patterns accurately is hindered by several factors:
    • Structural and Implementation Variants: Different ways to structure the same pattern.
    • Disparity in Results: Variations caused by different pattern specifications.
    • Implementation Divergence: Multiple ways to implement specific relationships.
    • Technical Limitations: Difficulties in detecting overlapping patterns and supporting multiple programming languages.
  • Singleton Variant Examples:
    • Accurately Identified: A standard implementation with a private static instance, private constructor, and a static getInstance() method returning the instance.
    • Inaccurately Recognized/Variant: Implementations where getInstance() returns a new Singleton() every time, or where the instance is stored in a hashtable rather than a standard static field.
  • Overlapping Patterns: Systems often contain overlapping roles (e.g., a class serving as both a component in an Adapter and a Proxy or Bridge), requiring processed informatics to distinguish them.

State of the Art: Classification and Approaches

  • Classification of Techniques:
    • Structural Analysis: Extraction of structural relationships.
    • Behavioral Analysis: Utilizing dynamic analysis, machine learning, and static program analysis.
    • Combined Structural and Behavioral: Aimed at reducing search space and improving accuracy.
    • Combined Structural, Behavioral, and Semantic: Designed to improve accuracy by specifically detecting false negatives.
  • Representative Current Approaches:
    • Gueheneuc et al. (PTIDEJ): Java; Constraint solver + Numerical Signature; 57%57\% precision.
    • Pattersson et al. (CrocoPat): Java; Database query; 75%75\% precision.
    • Lucia et al. (DPRE): Java; XPG formalism and LR parsing; 62%97%62\%-97\% precision.
    • Dong et al. (DP-Miner): Java; Matrix and Weight; 95%95\% precision.
    • Tsantalis et al. (DPD): Java; Similarity matrix; 100%100\% precision.
    • Shi and Olsson (PINOT): Java; Data/Control Flow; (Precision Not Mentioned - NM).
    • Nierre et al. (FUJABA): Java; Fuzzy logic and Dynamic analysis; (NM).
    • Smith and Scot (SPQR): C++; Rho-Calculus; (NM).

Requirement Elicitation for Advanced Recovery

  • Critical Review Findings: Existing tools often miss overlapping compositions, support only C++/Java, and suffer from a wide disparity in result accuracy across limited pattern sets.
  • Approach Requirements:
    • Req1: Improving accuracy.
    • Req2: Variant handling.
    • Req3: Overlapping detection.
    • Req4: Proper evaluation.
    • Req5: Multiple language support.

Proposed Concept of Approach

  • Key Concepts: The approach integrates multiple searching techniques and analysis methods with customizable pattern definitions to detect variants.
  • Scope: Covers all type of GoF (Gang of Four) patterns, specifically targeting structural design pattern overlapping.
  • Workflow Phases:
    • Phase I: Creating pattern definitions using feature types (customizable and comprehensible).
    • Phase II: Pattern recognition using SQL, source code parsers, and regular expressions.
  • Feature Type Parameters: Name, Query, Parameter, Count of previous result, Search method, and Report result.
  • Negative Feature Types: Used specifically to filter out false positives during the detection process.
  • Feature Reuse Examples:
    • Object Adapter: Requires features F1,F2,F3,F5,F7,F8F1, F2, F3, F5, F7, F8.
    • Class Adapter: Adds F2F2 (Has Inheritance between C2C2 and C3C3).
    • Proxy: Requires features F1,F2,F4,F5,F6,F8F1, F2, F4, F5, F6, F8.

Design Pattern Recovery Technique Details

  • Static Architecture View: The process flows from a reverse-engineered source code model (Java, .c, .cpp, etc.) to a SQL model. A recognition controller iterates through feature types, applying SQL queries, RegEx matchers, or code parsers.
  • Searching Technologies:
    • SQL: Extracts structural information from database models; requires internal knowledge of the data structure.
    • Regular Expressions (RegEx): Extracts source code info not present in the model; limited in handling nested information.
    • Source Code Parsers: Based on static analysis to extract behavioral information; requires specific effort for each new language.
  • Parser Module Architecture: Uses the Coco/R Parser Generator. It takes grammar files to generate scanners and parsers. A "Robust Scan" investigates language-specific code to generate specialized parsers for Delegation, Aggregation, and Method Invocation.
  • Annotations: Optional semantic tags (e.g., @compose, @decouple, @provide, @traverse) help reduce search space and improve identification of semantic roles.

Prototyping Tool (EA Add-In)

  • Features: Developed as an Add-In for the Enterprise Architect (EA) Modeling Tool. It uses a simple input/comprehensible output format and is scalable.
  • Abstract Architecture: Includes a Presentation Module for visualizing overlaps, a Pattern Matcher, and a Data/Code Module utilizing the Visual Studio .NET framework.
  • Visual Output: The tool identifies roles (Target, Adapter, Adaptee), verified properties, and overlaps (e.g., Bridge pattern overlapping with Adapter pattern).

Evaluation and Accuracy Metrics

  • Experimental Setup: Benchmarks include Junit 3.7, JHotDraw 5.1, JRefactory 2.6.24, QuickUML 2001, Apache Ant 1.6.2, Galb++ 2.4, and others in Java, C++, and C#.
  • Metric Formulas:
    • Precision (P): P=TPTP+FPP = \frac{TP}{TP + FP}. (If TP=FP=0TP = FP = 0, Precision is defined as 100%100\%).
    • Recall (R): R=TPTP+FNR = \frac{TP}{TP + FN}.
    • F-Score: F=(1+w2)×P×Rw2×P+RF = \frac{(1 + w^2) \times P \times R}{w^2 \times P + R}, where w=222.8w = 2\sqrt{2} \approx 2.8.
  • Results:
    • Junit 3.7: Precision 0.980.98, Recall 1.01.0.
    • Apache Ant: Precision 0.920.92, Recall 0.880.88.
    • Comparison to P-Mart: The approach (Thesis Result - TR) shows an overall improvement of 10%22%10\% \dots 22\% in F-Score compared to the P-Mart baseline across systems like JHotDraw and QuickUML.

Conclusions and Future Work

  • Conclusions: The integration of multiple search techniques improves precision/recall and allows for the customization of pattern definitions to handle structural/implementation variants.
  • Future Directions:
    • Extend to architectural and J2EE patterns.
    • Support additional programming languages.
    • Automate the translation of UML structures into pattern definitions.
    • Enhance visualization of compositions and overlapping patterns.
    • Integrate output formats with other software engineering tools.