|
DP-Miner A Tool for Design Pattern Recovery |
Objective
Design Patterns, as good solutions to recurring problems, are proved practically important and useful in the process of software development. They have been extensively applied in industry. They help to record design tradeoff, capture design decisions, and reuse expert experience. Many current software systems embed design pattern instances in system source code. When design patterns are applied and implemented in a system, however, the pattern-related information is usually lost in the source code. It is hard to trace such design information in source code. Recovering design pattern instances from system source code can greatly help to understand the systems and change them in the future.
Paper Related to the Tool
Jing Dong and Yajing Zhao, Experiments on Design Pattern Discovery, the Proceedings of the 3rd International Workshop on Predictor Models in Software Engineering (PROMISE), in conjunction with ICSE, Minneapolis, MN, USA, May 2007.
Jing Dong, Dushyant S. Lad and Yajing Zhao, DP-Miner: Design Pattern Discovery Using Matrix, the Proceedings of the Fourteenth Annual IEEE International Conference on Engineering of Computer Based Systems (ECBS), pages 371-380, Arizona, USA, March 2007.
DP-Miner
DP-Miner is intended to recover design patterns applied in software from source code. DP-Miner analyze structural, behavioral, and semantic characteristics of system and patterns. In structural analysis, DP-Miner presents system structure in a matrix with the columns and rows to be all classes in the system. The value of each cell represents the relationships among the classes. The structure of each design pattern is similarly represented in another matrix. The discovery of design patterns from source code becomes matching between the two matrices. If the pattern matrix matches the system matrix, a candidate instance of the pattern is found. Besides matrix, DP-Miner uses weight to represent the attributes/operations of each class and its relationships with other classes and compares system class weight to pattern class weight.
Standalone Version and Eclipse Plug-in Version
The standalone version of DP-Miner is available here.
Currently the standalone version is able to recover four patterns, namely, Adapter, Bridge, Composite, and Strategy, from software that are written in Java. We already conducted experiments on four open source systems, Java.Awt, JUnit, JEdit, and JHotDraw.
The Eclipse Plugin version of DP-Miner is available here.
This version, we propose to define the patterns to be discovered in an xml file. The Plugin version of the tool is able to take the system xml file (for example, junit.xml (Note: 3135KB, please use right click-->save as...)), as well as pattern xml file (for example, patterns.xml) as inputs. The tool will detect the instances for all the defined patterns from the system. Therefore this version is able to discover a broader range of patterns.
We use XML to define the structural characteristics, behavioral characteristics, as well as semantic characteristic of patterns. Currently, the example patterns.xml we provide includes the definition for Adapter, Bridge, Composite, Observer, and Strategy pattern. However, more patterns can be defined following the same format and be included.
Download the tool and unzip it. Put the folder under the eclipse/plugins directory and restart Eclipse, you will be able to see "Pattern" on the Menu. Click it and in the drop down menu items list, click System Matrix first, then locate a system XML file (i.e. junit.xml). After that the matrix describing the system properties appear in a view tab as shown in the following screen:
After system matrix has been calculated, click “Pattern” on the Menu and in the drop down menu items list, click “Discover Pattern”. Then locate a pattern file (i.e., patterns.xml). Then the pattern instances are detected and displayed in a view tab.
Results are shown in a panel as follows.
This version of the tool also has the functionality to add the detected pattern information back to the XML file. After the detection of each pattern, the original file is copied in the original folder and renamed to the original file name followed by “_modified”, i.e., original_file_name_modified.xml. Pattern information is added to the copied file. If you open such a file and search for “@”, you should be able to see the added pattern information.
Experiment Result
We have conducted experiments with our standalone tool on four open-source systems, namely Java.awt package, JUnit, JEdit, JHotDraw.
Table 1 Experiment Result of Detecting Strategy Pattern in JHotDraw
|
|
CONTEXT |
STRATEGY |
CONCRETE STATERGY |
|
|
[0] |
DrawApplet |
Drawing |
StandardDrawing |
T |
|
[1] |
DrawApplet |
Tool |
UndoableTool |
T |
|
[2] |
DrawApplet |
DrawingView |
StandardDrawingView, NullDrawingView |
F |
|
[3] |
PaletteButton |
PaletteListener |
DrawApplet, DrawApplication |
T |
|
[4] |
StorageFormatManager |
StorageFormat |
StandardStorageFormat |
T |
|
[5] |
UndoableAdapter |
DrawingView |
StandardDrawingView, NullDrawingView |
F |
|
[6] |
CommandButton |
Command |
UndoableCommand |
T |
|
[7] |
StandardVersionControlStrategy |
VersionRequester |
DrawApplet, DrawApplication |
T |
|
[8] |
UndoableHandle |
DrawingView |
StandardDrawingView, NullDrawingView |
T |
|
[9] |
UndoRedoActivity |
Undoable |
UndoableAdapter |
T |
|
[10] |
ToolButton |
Tool |
UndoableTool |
T |
|
[11] |
SelectionTool |
Tool |
UndoableTool |
T |
|
[12] |
AbstractTool |
DrawingEditor |
DrawApplet, DrawApplication, JavaDrawViewer |
T |
|
[13] |
AbstractTool |
DrawingView |
StandardDrawingView, NullDrawingView |
T |
|
[14] |
EventDispatcher |
Tool |
UndoableTool |
F |
|
[15] |
ConnectionTool |
ConnectionFigure |
LineConnection |
T |
|
[16] |
UndoActivity |
ConnectionFigure |
LineConnection |
T |
|
[17] |
AbstractCommand |
DrawingEditor |
DrawApplet, DrawApplication, JavaDrawViewer |
T |
|
[18] |
EventDispatcher |
Command |
UndoableCommand |
F |
|
[19] |
StandardDrawingView |
DrawingEditor |
DrawApplet, DrawApplication, JavaDrawViewer |
T |
|
[20] |
StandardDrawingView |
Drawing |
StandardDrawing |
T |
|
[21] |
StandardDrawingView |
Painter |
BufferedUpdateStrategy, FastBufferedUpdateStrategy, NullPainter, SimpleUpdateStrategy, ZoomUpdateStrategy, ClippingUpdateStrategy, PatternPainter |
T |
|
[22] |
StandardDrawingView |
PointConstrainer |
GridConstrainer |
T |
|
[23] |
DrawingViewKeyListener |
Command |
UndoableCommand |
T |
|
[24] |
AbstractFigure |
FigureChangeListener |
FigureChangeAdapter, FigureChangeEventMulticaster, HTMLTextAreaFigure, TextAreaFigure, TextFigure |
T |
|
[25] |
ChangeConnectionHandle |
ConnectionFigure |
LineConnection |
T |
|
[26] |
ConnectionHandle |
ConnectionFigure |
LineConnection |
T |
|
[27] |
DeleteFromDrawingVisitor |
Drawing |
StandardDrawing |
T |
|
[28] |
FigureAndEnumerator |
FigureEnumeration |
FigureEnumerator, ReverseFigureEnumerator, SingleFigureEnumerator |
T |
|
[29] |
HandleTracker |
Handle |
UndoableHandle |
T |
|
[30] |
HandleAndEnumerator |
HandleEnumeration |
HandleEnumerator |
T |
|
[31] |
InsertIntoDrawingVisitor |
Drawing |
StandardDrawing |
T |
|
[32] |
NullDrawingView |
DrawingEditor |
DrawApplet, DrawApplication, JavaDrawViewer |
T |
|
[33] |
DrawApplication |
Tool |
UndoableTool |
T |
|
[34] |
DrawApplication |
DrawingView |
StandardDrawingView, NullDrawingView |
T |
|
[35] |
DrawApplication |
Desktop |
MDIDesktopPane, JPanelDesktop, JScrollPaneDesktop, SplitPaneDesktop |
T |
|
[36] |
DragNDropTool |
Tool |
UndoableTool |
T |
|
[37] |
JHDDragSourceListener |
DrawingEditor |
DrawApplet, DrawApplication, JavaDrawViewer |
T |
|
[38] |
JHDDragSourceListener |
Undoable |
UndoableAdapter, UndoRedoActivity |
T |
|
[39] |
JHDDropTargetListener |
DrawingEditor |
DrawApplet, DrawApplication, JavaDrawViewer |
T |
|
[40] |
JHDDropTargetListener |
DrawingView |
StandardDrawingView, NullDrawingView |
T |
|
[41] |
JHDDropTargetListener |
Undoable |
UndoableAdapter, UndoRedoActivity |
T |
|
[42] |
DisposableResourceManagerFactory |
DisposableResourceHolder |
StandardDisposableResourceHolder |
T |
|
[43] |
DisposableResourceManagerFactory |
DisposableResourceManager |
StandardDisposableResourceManager |
T |
|
[44] |
ETSLADisposalStrategy |
DisposableResourceManager |
StandardDisposableResourceManager |
T |
|
[45] |
HTMLTextAreaFigure |
DisposableResourceHolder |
StandardDisposableResourceHolder |
T |
|
[46] |
StandardDisposableResourceManager |
ResourceDisposabilityStrategy |
ETSLADisposalStrategy |
T |
|
[47] |
TextHolderContentProducer |
TextHolder |
TextAreaFigure, TextFigure |
T |
|
[48] |
ZoomTool |
Tool |
UndoableTool |
T |
|
[49] |
CommandCheckBoxMenuItem |
Command |
UndoableCommand |
T |
|
[50] |
CommandMenuItem |
Command |
UndoableCommand |
T |
|
[51] |
CompositeFigureCreationTool |
CompositeFigure |
StandardDrawing, GraphicalCompositeFigure, PertFigure |
T |
|
[52] |
MDIDesktopPane |
DrawingView |
StandardDrawingView, NullDrawingView |
T |
|
[53] |
DesktopEventService |
DrawingView |
StandardDrawingView, NullDrawingView |
F |
|
[54] |
GraphicalCompositeFigure |
Layouter |
HTMLLayouter, SimpleLayouter |
T |
|
[55] |
MiniMapView |
DrawingView |
StandardDrawingView, NullDrawingView |
T |
|
[56] |
NestedCreationTool |
CompositeFigure |
StandardDrawing |
T |
|
[57] |
SimpleLayouter |
Layoutable |
GraphicalCompositeFigure |
T |
|
[58] |
TextAreaTool |
TextHolder |
TextAreaFigure, TextFigure |
T |
|
[59] |
WindowMenu |
Command |
UndoableCommand |
T |
|
[60] |
TextTool |
TextHolder |
TextAreaFigure, TextFigure |
T |
|
[61] |
Animator |
DrawingView |
StandardDrawingView, NullDrawingView |
T |
|
[62] |
Animator |
Animatable |
AnimationDecorator, BouncingDrawing |
T |
|
[63] |
JavaDrawViewer |
Drawing |
StandardDrawing |
F |
Table 2 Manually Found Strategy Pattern Instances in JHotDraw that are missed by DP-Miner
|
|
CONTEXT |
STRATEGY |
|
[1] |
LineConnection |
Connector |
|
[2] |
ChangeConnectionHandle |
Connector |
|
[3] |
ConnectionTool |
Connector |
|
[4] |
PolygonHandle |
Locator |
|
[5] |
LocatorHandle |
Locator |
|
[6] |
LocatorConnector |
Locator |
|
[7] |
SelectionTool |
DrawingView |
last updated: Oct 24, 2008
Please see our DP Miner Project page.