ICS Department
1 Design Patterns SWE 436
082
Design Patterns
Term Project
Team members:
TABLE OF CONTENT
LIST OF FIGURES ......................................................................................................................................... 3
1. Introduction .................................................................................................................................. 4
1.1. Reference Material ....................................................................................................................... 4
2. Tools .............................................................................................................................................. 4
2.1. PINOT ............................................................................................................................................ 4
2.1.1. Configuration ................................................................................................................................ 6
2.2. ExamDiff Pro ................................................................................................................................. 6
2.2.1. Configuration ................................................................................................................................ 7
2.3. Understand ................................................................................................................................... 8
2.3.1. Configuration ................................................................................................................................ 8
3. Analysis ......................................................................................................................................... 8
3.1. jEdit 4.0 ......................................................................................................................................... 9
3.1.1. LCOM and CBO Analysis .............................................................................................................. 11
3.2. jEdit 4.2 ....................................................................................................................................... 13
3.2.1. LCOM and CBO Analysis .............................................................................................................. 15
3.3. Conclusion ................................................................................................................................... 16
4. AppenDIX .................................................................................................................................... 17
4.1. Appendix I: jEdit 4.0 .................................................................................................................... 17
4.2. Appendix II: jEdit 4.2 ................................................................................................................... 17
3 Design Patterns
LIST OF FIGURES
Figure 1 Comparison Option in ExamDiff Pro ................................................................................................. 7
Figure 2 Filter Option in ExamDiff Pro ............................................................................................................ 8
Figure 3 ........................................................................................................................................................... 9
Figure 4 ......................................................................................................................................................... 10
Figure 5 ......................................................................................................................................................... 10
Figure 6 ......................................................................................................................................................... 11
Figure 7 ......................................................................................................................................................... 11
Figure 8 ......................................................................................................................................................... 12
Figure 9 ......................................................................................................................................................... 12
Figure 10 ....................................................................................................................................................... 13
Figure 11 ....................................................................................................................................................... 14
Figure 12 ....................................................................................................................................................... 14
Figure 13 ....................................................................................................................................................... 15
Figure 14 ....................................................................................................................................................... 15
Figure 15 ....................................................................................................................................................... 16
Figure 16 ....................................................................................................................................................... 16
4 Design Patterns
1. INTRODUCTION
In this project we took a closer look at an open-source system “jEdit” examining the
design patterns at the source code level. This report will show our findings and how
can the use of design patterns affect the stability of a system. It will compare three
versions of jEdit and show how the number of design patterns changed from one
release to another and how stable each version from the other ones. The analysis in
this report is limited to the accuracy of PINOT tool that automate the process of
finding design patterns in Java source code.
2. TOOLS
2.1. PINOT
PINOT is a tool that detects the occurrence of most Gang of Four design patterns
(GoF). It takes as an input a java file or paths to java files, and generates a report
of the design patterns found in the system with some statistics. Here is part of an
output from running PINOT on jEdit4.0:
Singleton Pattern
ReflectManager is a Singleton class
rfm is the Singleton instance
getReflectManager creates and returns rfm
File location: /Users/sophto_92/Desktop/SWE436
Project/jEdit/jEdit4.0/bsh/ReflectManager.java
----------
Chain of Responsibility Pattern
RE is a Chain of Responsibility Handler class
setUncle is a handle operation
lastToken of type REToken propogates the request
File Location: /Users/sophto_92/Desktop/SWE436 Project/jEdit/jEdit4.0/gnu/regexp/RE.java
Decorator Pattern
RETokenRepeated is a Decorator class
getMinimumLength is a decorate operation
token of type REToken is the Decoratee class
File Location: /Users/sophto_92/Desktop/SWE436
Project/jEdit/jEdit4.0/gnu/regexp/RETokenRepeated.java
………
------------------------------------------
Creational Patterns
==============================
Abstract Factory 3
Factory Method 4
Singleton 1
------------------------------
Structural Patterns
==============================
Adapter 6
Bridge 1
Composite 5
Decorator 2
Facade 20
Flyweight 15
Proxy 13
------------------------------
Behavioral Patterns
==============================
6 Design Patterns
Chain of Responsibility 3
Mediator 64
Observer 2
State 0
Strategy 7
Template Method 0
Visitor 0
------------------------------
nMediatorFacadeDual/nMediator = 4/64
nImmutable/nFlyweight = 9/15
nFlyweightGoFVersion = 0
2.1.1. Configuration
To run PINOT on your machine you first need to have a Unix-based system
running. Then do the following steps:
1. After extracting the downloaded file.
2. > cd pinot
3. > ./configure --prefix=PREFIX --enable-debug
4. > make
5. > make install
6. The executable file pinot is located in PREFIX/bin (e.g: /Users/bin/)
7. To run PINOT you need to include rt.jar in the classpath :
./pinot -classpath /Users/admin/pinot/lib/rt.jar
/Users/admin/Desktop/jEdit/RE.java
When you want to supply to PINOT a collection of java files, you can put
them in a text file then execute this command:
./pinot -classpath /Users/admin/pinot/lib/rt.jar
@/Users/admin/Desktop/jEdit/jEdit.txt
from other comparison programs. ExamDiff Pro offers a much more efficient and
user-friendly way to compare files and folders.
2.2.1. Configuration
In ExamDiff Pro, we included in the comparison only the java files and
excluded many things like comments and so on, See the pictures below.
After you configured the tool, run a “Full Comparison” to get accurate result
of what has changed and what has not changed.
2.3. Understand
Understand helps programmers to quickly comprehend measure, maintain and
document their source code. For many, especially those working on large,
multiple MSLOC projects, it has become an indispensable tool.
2.3.1. Configuration
After installing Understand, you only need to give as an input the root
directory to the source code. Then the tool will generate the report in an
HTML and RTF formats.
For more information about the tool visit:
http://www.scitools.com/products/understand/
3. ANALYSIS
In this section we will examine the matrices collected from Understand and
ExamDiff against the stability (changeability) of Object Oriented Design Patterns.
The matrices are collected from jEdit 4.0 and jEdit 4.2 source codes. As a result jEdit
4.0 is compared against jEdit 4.2 and jEdit 4.2 is compared against jEdit 4.3. This
analysis focus on how stable to use design pattern and uses comparison techniques
9 Design Patterns
between the stability of the classes participate in design patterns and classes that do
not participate in design pattern. Two main matrices we used of the classes
relatedness which are CBO Count of Coupling Between Objects and LCOM
Percent Lack of Cohesion of Methods. This analysis accuracy relays on the Pinot
accuracy of detecting design patterns as mentioned in the introduction.
Figure 3
Figure 4
Figure 5
We need to analyze which pattern (or type of pattern) is tending to be more stable
than the others. The statistics, Figure6, Figure7, shows that Factory, Façade and
Strategy have the highest percentage of change over the other patterns (Even
though singleton has percentage of 100% change but it occurs once in the
system). Flyweight is tend to be the most stable pattern in the jEdit 4.0 since it has
only 28% change with the number of occurrences 15 (Even though Decorator and
Bridge has percentage of 100% not change but it occurs only once and twice
respectively in the system). Creational patterns seem to have the highest
percentage of change among the other type of patterns with percentage of 83%.
This percentage is affected by the factory pattern since it has 80% percentage of
11 Design Patterns
change and number of occurrence 4. The Structural pattern has the minimum
percentage of changes with 56%.
Figure 6
Figure 7
CBO among the other types of patterns since the bridge pattern has the
highest percentage in both LCOM and CBO which are 95% and 24%
respectively. This concludes that the system classes relays on the Structural
pattern more than the other types. Taking in the consideration the Structural
pattern percentage of change, we do not expect that the overall classes will
change significantly. See Figure8 and Figure9 below.
Figure 8
Figure 9
13 Design Patterns
Figure 10
Figure 11
Figure 12
We need to analyze which pattern (or type of pattern) is tending to be more stable
than the others. The statistics, Figure13, Figure14, shows that Proxy and
Flyweight have the highest percentage of change over the other patterns. The
other patterns are much more stable in jEdit 4.2 since the number of added
patterns has increased significantly.
15 Design Patterns
Figure 13
Figure 14
Figure 15
Figure 16
3.3. Conclusion
Design patterns occurrence increased with each release.
17 Design Patterns
Even though design patterns affect the performance and it is hard to evaluate
stability, but we think it increases the stability of the system.
LCOM and CBO should be taken in the consideration.
The trend from one release to another in jEdit (4.0 4.2 4.3) is that the
classes participating are less changeable than other classes and their occurrence
is increasing. This made us conclude that using design pattern is very good in
solving common problem in the design.
Finally, developer should spend more time investigating the applicability of a
certain design pattern to apply it only in the correct place. It also should be
commented what type of patterns are used and where for later maintenance and
evaluation studies.
4. APPENDIX