27.03.2014 Views

SEKE 2012 Proceedings - Knowledge Systems Institute

SEKE 2012 Proceedings - Knowledge Systems Institute

SEKE 2012 Proceedings - Knowledge Systems Institute

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Our approach checks whether there is one of the following<br />

dependence relations in SDG of Notify candidate: (1) Notify<br />

method creates an object, and a parameter of Update depends<br />

on the object; (2) some fields of Observer depend on fields of<br />

Subject.<br />

B. Case Study<br />

Fig. 3 shows an Observer instance identified by JDP-<br />

Detector from open source software JEdit 4.3.2. In the instance,<br />

HelpHistoryModel and HelpHistoryModelListener act as Subject<br />

and Observer, respectively, and fireUpdate is the candidate<br />

of Notify method. JDP-Detector finds that there are dependence<br />

paths between fields of HelpHistoryModel and HelpHistory-<br />

ModelListener in SDG of fireUpdate. This indicates that<br />

fireUpdate acts as Notify method. Correspondence between<br />

Observer fields and Subject fields can be observed by following<br />

the dependence paths: HelpHistoryModelListener._back is<br />

the observed result of target HelpHistoryModel.historyPos, and<br />

HelpHistoryModelListener._forward is th e observed result of<br />

targets HelpHistoryModel.history and HelpHistoryModel.historyPos.<br />

Context has an adapting method, which delegates its duty to<br />

State, while in Strategy pattern, Context only invokes the algorithm<br />

encapsulated in Strategy, the invocation doesn't need to<br />

be an adapting method. This identification standard is not apparent<br />

according to descriptions in [1], but it brings good identification<br />

result in our experiment.<br />

JDP-Detector identifies 37 Strategy instances, 35 of which<br />

are TP, and the precision is 94.6%. It also identifies 8 State<br />

instances, 6 of which are TP, and the precision is 75%.<br />

Table I shows the recognized State instances. Manual analysis<br />

reveals that instances 3 and 8 in Table I are Adapter and<br />

Strategy instances respectively.<br />

TABLE I.<br />

STATE INSTANCES IDENTIFED BY JDP-DETECTOR<br />

Context State Manual<br />

1 AbstractConnector Figure T<br />

2 AbstractTool DrawingView T<br />

3 ConnectionHandle Figure F<br />

4 LocatorHandle Locator T<br />

5 PolygonHandle Locator T<br />

6 StandardDrawingView Drawing T<br />

7 StandardDrawingView DrawingEditor T<br />

8 StandardDrawingView Painter F<br />

Figure 3. An Observer Instance in JEdit 4.3.2<br />

V. EXPERIMENT<br />

This section reports the results of pattern instance identification<br />

in JHotDraw 5.1 (8.3 KLOC, 173 classes) using JDP-<br />

Detector, and compares it with the results reported by some<br />

other researches taking JHotDraw 5.1 as experimental subject.<br />

A. Identification of Adapter Pattern Instances<br />

JDP-Detector finds 17 Adapter instances, 14 of which are<br />

TP (true positive), and the precision is 82.35%. The 3 FP (false<br />

positive) are two Strategy instances and a Decorator instance.<br />

These patterns' structures are similar to that of Adapter, and<br />

adapting behavior is permitted to exist in the two patterns.<br />

M. von Detten et al. obtain 67 instances using fuzzy metric<br />

[13]. They do not manually check the result, only figure out<br />

that the result contains some repeated instances, and instances<br />

with low membership degree is not eliminated. A. De Lucia et<br />

al. get 41 instances using structure information [8]. N. Tsantalis<br />

et al. identify pattern instances using similar scoring of structure<br />

graph, and recognizes 23 instances without distinguishing<br />

Strategy pattern from Command pattern [5]. Result of [5] is a<br />

subset of that of [8], and our result is a subset of that of [5]. In<br />

other words, we adopt a stricter identification standard.<br />

B. Identification of State and Strategy Instances<br />

State instances and Strategy instances are difficult to distinguish<br />

in existing researches. We believe that, in State pattern,<br />

Due to space limitation, the recognized Strategy instances<br />

can't be listed, two FP of which are Command and Adapter<br />

instances respectively. The Command instance is recognized<br />

because it has similar structure with Strategy pattern. The<br />

Adapter instance (ChangeConnectionHandle/Figure) recognized<br />

as Strategy instance is the same one as item 3 of Table I, as<br />

ChangeConnectionHandle is a subclass of ConnectionHandle.<br />

This FP is identified because JDP-Detector fails to take the<br />

inherited methods of the analyzed class into account.<br />

N. Tsantalis et al. identify 22 instances using DPD without<br />

distinguishing State from Strategy [5]. Y. Guéhéneuc et al.<br />

infer structure characteristic of design pattern using machine<br />

learning and get 2 State instances and 4 Strategy instances [6].<br />

A. De Lucia et al. get 43 Strategy instances (the precision is<br />

46.51%) and 36 State instances (the precision is 5.6%) using<br />

both structure information and method call sequence information<br />

[7]. Based on the comparison, we can conclude that our<br />

approach is much more successful in distinguishing State instances<br />

from Strategy instances.<br />

C. Identification of Observer Instances<br />

As illustrated in Table II, JDP-Detector identifies 4 Observer<br />

instances, and reports the notified event objects in each instances.<br />

Three of them are TP, and the precision is 75%. Instance<br />

4 in Table II is a FP, which contains event notifying<br />

behavior, but no one-to-many broadcast behavior.<br />

A. De Lucia et al. identify 9 Observer instances using their<br />

tool DPRE [7]. Five of the nine instances are TP, and the precision<br />

is 55.56%. We compare these instances with our result,<br />

and find that three of their instances (Drawing/Drawing-<br />

ChangeListener, StandardDrawing/DrawingChangeListener,<br />

Drawing/DrawingView) are actually the same one as instance 2<br />

of Table II. Moreover, we find a instance (Connector/ConnectorFigure)<br />

identified by DPRE is not a TP, because it neither<br />

291

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!