デザインパターン検出

Flexible Design Pattern Detection
Based on Feature Types
Ghulam Rassol (COMSATS Institute of Information, Pakistan)
Patrick Mader (Johannes Kepler University, Austraria)
FSE/ASE2011 勉強会
担当者: 某社・有志 吉村 健太郎
1/5

技術領域:デザインパターン検出
(Design Pattern Detection (Mining, Recoveryとも))


デザインパターン
 ソフトウェアシステム開発の定石集
 例:Factory Pattern, Adapter Patternなど(GoF)
デザインパターン「検出」
 既存システムからデザインパターン適用/合致箇所を抽出
 プログラム理解、保守開発(機能追加/変更)を支援
Existing System
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Adapter Pattern
Factory Patter
Summary of “Ghulam Rassol and Patrick Maeder, Flexible Design Pattern Detection Based on Feature Types, ASE2011.”
2/5
 デザインパターン検出研究における主要な貢献
No. 従来研究の課題
提案手法の特徴
1 「デザインパターン」 Feature Typesでパターンを定義し、
拡張・カスタマイズ可能にした
統一定義が無い
2 共通問題および
正解集が無い
従来研究を調査し、信頼できる
ベースラインを導入した
3 言語依存
言語によらず拡張可能
4 GoFパターンの
一部のみ検出
GoF全パターン(23種類)を検出可
(適合率、精度ともに向上)
 No.1が本論文の主要課題

例えば「Factory Pattern」の実装は9種類ある
Product
Creator
Product
+FM1()
+FM2()
Creator
Product
+FM1()
+FM2()
Creator
+FM1()
+FM2()
・・・
ConcreteProduct
ConcreteCreator
-FM1()
-FM2()
ConcreteProduct
ConcreteCreator
-FM1()
-FM2()
ConcreteProduct
ConcreteCreator
-FM1()
-FM2()
Summary of “Ghulam Rassol and Patrick Maeder, Flexible Design Pattern Detection Based on Feature Types, ASE2011.”
3/5
 提案検出手法の概要
Feature type
定義
Refer to
Reverse engineered
source code model
2) Apply recognition SQL model
technology according analysis
Model and code
to feature type
RegEx matcher
1) Iterate through
Annotation
features of a
Recognition
Analyzer
pattern definition
controller
Feature specific
Code parser
3) Prune and expand
…
recognized patterns
based on results for
feature currently
Multiple recognition
under inspection
Technique depending on
Searched feature
パターン
定義
Source code model
E
B
A
+m1
+m2
G
D
+m3
C
F
+m1
+m2
+m3
Extracted
from
.java; .c;
.cpp; …
Inspected
source code
抽出(候補)
パターン
Summary of “Ghulam Rassol and Patrick Maeder, Flexible Design Pattern Detection Based on Feature Types, ASE2011.”
4/5
 検出例(Factory
Pattern)
Type Definition
FT1 Has class()
Returns: list of classes
FT2 Has super class(class)
Returns: list of classes
FT3 Have common method(class1, class2)
Returns: list of methods
FT4 Is returning class(method1)
Return: class
FT5 Is realizing interface(class1)
Returns: list of interfaces
FT6 Are generalized(class1, class2)
Returns: boolean value
FT7 Are aggregated(class1, class2)
Returns: boolean value
Source
code
(C++, Java)
Search (Example)
HasClass()
Result (Example)
A, B, C, D, F, G
HasSuperClass(A, B, C, D, F, G)
{C, B}, {G, F}
HaveCommonMethod({C, B}, {G,F}) {C, B, m1}, {C, B, m2}, {G, F, m3}
IsReturningClass(m1, m2, m3)
{C, B, m1, F}, {C, B, m2, D}
IsRealizingInterface(F, D)
{C, B, m1, F, E}
NOT(AreGeneralized(C, F))
{C, B, m1, F, E}
NOT(AreGeneralized(C, E))
{C, B, m1, F, E}
query
return
Recover Source code model
E
B
A
+m1
+m2
G
D
+m3
C
+m1
+m2
F
+m3
Summary of “Ghulam Rassol and Patrick Maeder, Flexible Design Pattern Detection Based on Feature Types, ASE2011.”
5/5