Upload
mohannad-shahat
View
581
Download
0
Embed Size (px)
DESCRIPTION
In this project we took a closer look at an open-source system “jEdit” examining thedesign patterns at the source code level. This report will show our findings and howcan the use of design patterns affect the stability of a system. It will compare threeversions of jEdit and show how the number of design patterns changed from onerelease to another and how stable each version from the other ones. The analysis inthis report is limited to the accuracy of PINOT tool that automate the process offinding design patterns in Java source code.
Citation preview
1 Design Patterns
King Fahd University of Petroleum and Engineering
ICS Department
SWE 436
082
Design Patterns Term Project
Team members:
Mohannad Shahat 244698 Feras AlTurigi 244638 Hosain Alhasmy 244126
2 Design Patterns
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.
1.1. Reference Material
1. jEdit4.0.txt (PINOT output)
2. jEdit4.2.txt (PINOT output)
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: ./pinot -classpath /Users/sophto_92/Downloads/2009-05-16/pinot/lib/rt.jar @/Users/sophto_92/Desktop/SWE436\ Project/jEdit/jEdit4.0/FilesList.txt --------- Original GoF Patterns ---------- 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 Primitive is a Chain of Responsibility Handler class toString is a handle operation value of type Object propogates the request File Location: /Users/sophto_92/Desktop/SWE436 Project/jEdit/jEdit4.0/bsh/Primitive.java
5 Design Patterns
Chain of Responsibility Pattern REToken is a Chain of Responsibility Handler class dumpAll is a handle operation next of type REToken propogates the request File Location: /Users/sophto_92/Desktop/SWE436 Project/jEdit/jEdit4.0/gnu/regexp/REToken.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 Chain of Responsibility Pattern RE is a Chain of Responsibility Handler class match is a handle operation firstToken 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 ……… ------------------------------------------ Pattern Instance Statistics: 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 ------------------------------ Number of classes processed: 239 Number of files processed: 312 Size of DelegationTable: 5161 Size of concrete class nodes: 175 Size of undirected invocation edges: 256 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
For more information about the tool visit: http://www.cs.ucdavis.edu/~shini/research/pinot/
2.2. ExamDiff Pro
ExamDiff Pro is a powerful yet intuitive and easy to use visual file and directory
comparison tool. It features unique functionality that distinguishes ExamDiff Pro
7 Design Patterns
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.
Figure 1 Comparison Option in ExamDiff Pro
8 Design Patterns
Figure 2 Filter Option in ExamDiff Pro
For more information about ExamDiff Pro visit: http://www.prestosoft.com/edp_examdiffpro.asp
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.
3.1. jEdit 4.0
In the statistics collected, Figure3, from jEdit 4.0 shows that 40% of the system
classes are participating in design patterns whereas 60% of the system classes are
not participating in design patterns. This will lead to the comparison between the
two types of classes against changes in the jEdit 4.2.
Figure 3
As appears in the statistics, Figure4, Figure5, the changes of the participate
classes is 65% to the overall participate classes while the changes in not
participate classes is 72% of the overall not participate classes. Since the classes
that participate in patterns has less percentage than the classes that are not
participate in patterns, we can conclude that the classes participate in patterns are
tend to be more stable from jEdit 4.0 to jEdit 4.2 than the classes that are not
participate in patterns.
10 Design Patterns
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
3.1.1. LCOM and CBO Analysis
LCOM and CBO should be low as much as possible to achieve better design.
However, Structural design pattern tends to have the highest LCOM and
12 Design Patterns
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
3.2. jEdit 4.2
The overall number of classes has increased in the jEdit 4.2. In the statistics,
Figure10, collected from jEdit 4.2 shows that 38% of the system classes are
participate in design patterns whereas 62% of the system classes are not
participate in design patterns. This will lead to the comparison between the two
types of classes against changes in the jEdit 4.3.
Figure 10
As appears in the statistics, Figure11, Figure12, the changes of the participate
classes is 24% to the overall participate classes while the changes in not
participate classes is 59% of the overall not participate classes. As it appears
adding more patterns drops the percentage of change significantly. Since the
classes that participate in patterns has less percentage than the classes that are not
participate in patterns, we can conclude that the classes participate in patterns are
tend to be more stable from jEdit 4.2 to jEdit 4.3 than the classes that are not
participate in patterns.
14 Design Patterns
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
3.2.1. LCOM and CBO Analysis
Behavioral design pattern tends to have the highest LCOM and CBO among
the other types of patterns since the Visitor pattern has the highest
percentage in both LCOM and CBO which are 89% and 31% respectively.
This concludes that the system classes relays on the Behavioral pattern more
than the other types. See Figure15 and Figure16 below.
16 Design Patterns
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
4.1. Appendix I: jEdit 4.0
4.2. Appendix II: jEdit 4.2