同様のバグを含むコード 検出手法の提案

Towards an Assessment of
the Quality of Refactoring Patterns
Norihiro Yoshida, Masatomo Yoshida, Katsuro Inoue
Osaka University, Japan
Department of Computer Science,
Graduate School of Information Science & Technology,
Osaka University
1
Refactoring

Refactoring is a process of restructuring an
existing code.
software’s internal structure without changing its
external behavior
 Improve the maintainability of software
 Alter

Example of Refactoring
 Merging
code clones into a new method
New method
Call statements
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
2
Refactoring Pattern

Typical process of restructuring existing
code
 Extract

Method, Pull Up Method, Extract Class
Each refactoring pattern includes
 refactoring
a
set of code fragments that should be refactored
 procedure

opportunity (bad smell)
to perform refactoring
how to perform refactoring
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
3
Literatures for Refactoring Patterns

A lot of refactoring patterns are proposed in
several literatures.
 M.
Fowler, Refactoring: improving the design of
existing code. Addison Wesley, 1999.
 M. Fowler, http://refactoring.com/ (93 patterns)
 J. Kerievsky, Refactoring to Patterns. Addison
Wesley, 2004. (27 patterns)
However, the quality of each refactoring pattern
is mostly never assessed.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
4
Overview of Our Research

Propose the following quality characteristics
of refactoring patterns
 Number
of Refactoring Opportunities
 Ease of Refactoring

Perform a case study on assessing those
quality characteristics
A
case study on Introduce Polymorphic Creation
with Factory Method [1] that is a kind of Pull Up
Method
Department of Computer
Science, Graduateto
School
of InformationAddison
Science & Technology,
Osaka University
[1] J. Kerievsky,
Refactoring
Patterns.
Wesley,
2004
5
Propose Quality Characteristics of
Refactoring Patterns

Number of Refactoring Opportunities
 What
kind of refactoring opportunities are
involved in software systems?

Ease of Refactoring
 It
means that ease of applying each refactoring
pattern to refactoring opportunities in source code.
 We focus on “Whether or not each refactoring
pattern involves enough description to perform
refactoring easily”.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
6
Case Study
Target Refactoring Pattern (1/2)

We assess the quality characteristics of Introduce
Polymorphic Creation with Factory Method.
Before Refactoring
junit::framework::TestCase
Condition 1
DOMBuilderTest
XMLBuilderTest
testAddAboveRoot
testAddAboveRoot
Similar methods belong to classes that
have a common parent class.
Condition 2
・・・
builder = new DOMBuilder(…);
・・・
Only difference among similar methods
is an object creation step.
・・・
builder = new XMLBuilder(…);
・・・
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
7
Case Study
Target Refactoring Pattern (2/2)

We assess the quality characteristics of Introduce
Polymorphic Creation with Factory Method.
Before Refactoring
After Refactoring
junit::framework::TestCase
junit::framework::TestCase
AbstractBuilderTest
#builder: OutputBuilder
DOMBuilderTest
XMLBuilderTest
testAddAboveRoot
It’s
easy to addtestAddAboveRoot
new test
class.
・・・
builder = new DOMBuilder(…);
・・・
・・・
builder = new XMLBuilder(…);
・・・
createBuilder
testAddAboveRoot
Factory Method:
Creator
・・・
builder = new
createBuilder(“orders”);
・・・
Factory Method:
ConcreteCreator
DOMBuilderTest
XMLBuilderTest
createBuilder
createBuilder
return new DOMBuilder(…);
return new XMLBuilder(…);
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
8
Case Study
Automation of Identifying Opportunities

We developed an automated tool that identifies opportunities.
Condition 1
Before Refactoring
junit::framework::TestCase
Similar methods belong to classes that
have a common parent class.
Step 1
DOMBuilderTest
XMLBuilderTest
testAddAboveRoot
testAddAboveRoot
Detect similar methods using a code
clone detection tool CCFinder
Condition 2
・・・
builder = new DOMBuilder(…);
・・・
・・・
builder = new XMLBuilder(…);
・・・
Only difference among similar methods
is an object creation step.
Step 2
Evaluate whether detected methods
include object creation statements
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
9
Case Study
Number of Refactoring Opportunities
Target
LOC
# classes
# opportunities
Target Pattern for
Pull
UpUp
Method
17.9% of the refactoring opportunities
Pull
ANTLR
1
Method are 32K
also for 167
Introduce Polymorphic
Creation33
Ant
198K
2
23
with Factory
Method.994
Azureus
538K
2226
20
42
jEdit
168K
922
0
1
JHotDraw
487
1
26
Developers 90K
should inspect
whether refactoring
SableCC
35K
0
opportunities
for Pull237
Up Method are also
are also 1
Soot
352K
2298
5 Factory
for Introduce
Polymorphic
Creation with
53
Method.
WALA
22
210K
1565
7
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
10
Case Study
Ease of Refactoring
1.
2.
Apply the target pattern to the refactoring
opportunities in Ant and ANTLR.
Confirm the steps that are not described in
the description of the target pattern.
We did not have to apply additional steps that are
not described in the description of the target pattern.
In terms of the ease of refactoring, the quality of the
pattern presentation is enough.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
11
Summary & Future Work

Summary
 Two
quality characteristics of refactoring
patterns
 A case study on assessing those quality
characteristics

Future Work
 Assess
other refactoring patterns
 To
compare refactoring patterns in terms of proposed
quality characteristics
 Discuss
change in maintainability
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University
12