You are on page 1of 4

(IJCNS) International Journal of Computer and Network Security, 11

Vol. 2, No. 1, January 2010

MCDMfJ : Mining Creational Design Motifs from


Java source code
Praneeth Kumar G1, Aditya Kumar K2
1
Corresponding Author,
Department Of Computer Science And Engineering,
Medha College Of Engineering,
Bibinagar, Andhra Pradesh, India
praneethkumar@hotmail.com
2
Department Of Computer Science And Engineering,
Krishna Murthy Institute Of Engg. & Tech.,
Ghatkesar, Andhra Pradesh, India
Kommera_adi@yahoo.com

Abstract: Design patterns are important in object-oriented implementation of the model. Section 7 shows the results on
programming because they offer design motifs, elegant solutions applying the model.
to recurrent design problems, which improve the quality of
software systems. Design motifs facilitate system maintenance by
2. GOF CREATIONAL PATTERNS
helping maintainers to understand design and implementation.
Erich Gamma, Richard Helm, Ralph Johnson and John
However, after implementation, design motifs are spread
throughout the source code and are thus not directly available to Vlissides with a foreword by Grady Booch. Often called as
maintainers. We present MCDMfJ, a tool to semiautomatically Gang of Four(GoF). GoF Creational patterns are Abstract
identify microarchitectures that are similar to creational design Factory , Builder , Factory Method, Prototype, Singleton.
motifs in source code and to ensure the traceability of these
microarchitectures between implementation and design. Thee Abstract Factory provides an interface for creating families
model followed consists of two layers: first layer to recover an
of related or dependent objects with out specifying their
abstract model of the source code, including binary class
relationships, and another layer to identify design patterns in the concrete classes.
abstract model.
Builder separates the construction of a complex object from
Keywords: Design pattern Identification. Design patterns in its representation so that the same construction process can
Java, Interclass Relationships. create different representations.

1. Introduction Factory Method defines an interface for creating an object,


but let subclasses decide which class to instantiate.
A major task in software comprehension is the
understanding of its design and architecture. As software Prototype specify the kinds of objects to create using a
can get large, this task should be supported by tools prototypical instance, and create new objects by copying this
performing automatic analyses. Design, however, is hard to purpose.
detect automatically, as it is not tangible. Fortunately,
standard solutions to solve certain design problems have Singleton ensures a class has one instance, and provide a
been established. These design patterns are described global point of access to it.
together with the design problem(s) they intend to solve [1]. Most GoF patterns have concrete definitions on their
Many of them have been formalized, for example to realization in code structure and system behavior. Such
introduce them automatically into software [2]. If it were concrete definitions are traceable.
possible to detect these patterns in software systems, one
would be able to deduce the intended design.
3. Juxtaposition of current approaches
GoF creational patterns encapsulate standard ways of
These approaches analyze inter-class relationships to
creating objects in object-oriented design. The GoF
identify the structural aspect of patterns, regardless of their
catalogue describes, using a standard but informal notation,
behavioral aspect. The targeted inter-class relationships
five such patterns, each of which offers different features.
include: class inheritance; interface hierarchies; modifiers of
classes and methods; types and accessibility of attributes;
The rest of this paper is organized as follows :
Section 2 deals with a brief description of GoF creational
method delegations, parameters and return types. Some
Patterns . Section 3 juxtaposes the current pattern detection
approaches first extract inter-class relationships from source
tools. Section 4 presents the microarchitectures of different
code and then perform pattern recognition based on the
patterns. Section 5 and 6 gives a brief structure and
12 (IJCNS) International Journal of Computer and Network Security,
Vol. 2, No. 1, January 2010
extracted information. For example, DP++ [15], SPOOL
[14], Osprey [16], and Reference [13] extract interclass
relationships from C++ source to a database; patterns are
then recovered through queries to the database. Reference
combines the Columbus reverse-engineering framework
with the MAISA architectural metrics analyzer (which
analyzes software at the design level and had reported
limited results on recovering anti-patterns [12]) to build a
pattern recognizer. However, pattern recognition requires
analyzing program behavior, which can be abstracted away
at the design level. Reference [2] use the Columbus schema
for the extracted abstract semantics graphs (ASG) and
recover patterns based on graph comparison. Reference [11] Factory method :
extracts inter-class relationships and then uses software
metrics to reduce search space. SOUL [10] is a logic
inference system, which has been used to recognize patterns
(in Java and SmallTalk) based on inter-class-based code
idioms and naming conventions. SPQR [9] uses
denotational semantics to find patterns on the ASG obtained
by gcc. The accuracy of these approaches depends in part on
the capability of the program facts extractors they use.
FUJABA [7] extends the work from [8] and uses a bottom-
up-top-down approach to speed up the search and to reduce
the false positive rate (due to more complicated inter-class
relationship, such as aggregation [8,7]). It uses a
combination of inter-class relationships to indicate a pattern.
Thus, when such information is obtained from the bottom-
up search, even partially, FUJABA assumes the existence of
a possible pattern and tries to complete the rest of the
search—i.e., the top-down search—to confirm that such a
pattern actually exists. This iterative approach allows going
back to their annotated abstract syntax tree (AST) for Prototype Pattern :
further analysis on demand.

4. Micro Architectures Of GoF Creational


patterns

Abstract Factory pattern :

Singleton Pattern :

Builder Pattern :
(IJCNS) International Journal of Computer and Network Security, 13
Vol. 2, No. 1, January 2010
5. MCDMfJ : A Bi-layered Approach reference for the Singleton instance also acts as the flag) and
boolean are more common. Although a flag may be an
MCDMfJ relies on a bi-layered approach, detailed in integer, it is not as common in this case and would require
the following sections. This model is developed on the basis much more computation
of reference[17], DEMIMA, Which is a generalized one for MCDMfJ only analyzes lazy instantiation that uses
identifying Design patterns from any kind of Source code. boolean or java.lang.Object types. Inter-procedural data-flow
and alias analyses are only used for detecting patterns that
5.1 First Layer : Source Code Model often involve method delegations in practice, such as
The first layer consists of an infrastructure, e.g., parsers, to Abstract Factory, Factory Method.
Obtain models Ms of the source code of system. It includes
all the constituents found directly in any Java object-orinted
system: class, interface, member class and interface, 7. Results and Analysis
method, field, implementation and inheritance relationships, We compared MCDMfJ with three other similar tools:
and rules containing their relationships. The constituents PINOT[1], HEDGEHOG [4] and FUJABA 4.3.1 (with
describe the structure of systems and a subset of their Inference Engine version 2.1).HEDGEHOG reads pattern
behavior. We have implemented this layer in java. specifications from SPINE, which allows users to specify
inter-class relationships and other path-insensitive semantic
5.2 Second Layer : Design-Level Model analysis (e.g., for Factory Method pattern, the predicate
In this layer, we first describe a model MDM of a design “instantiates(M, T)” checks whether a method M creates
motif with java, then MCDMfJ looks for the micro- and returns an instance of type T.), but other more
architectures similar to the design motif we described complicated semantic analysis is hard-wired to its built-in
earlier. predicates (e.g., “lazyInstantiates(...)”). Thus, SPINE is
bounded by the capability of semantic analysis provided by
6. Implementation HEDGEHOG. To use the tool, the user specifies a target
class and a target pattern to verify against (i.e., attempt to
Based on our methodology (Section 5), we have recognize).
implemented a fully automated pattern detection tool, called
MCDMfJ (Mining Creational Design Motifs form Java
Source code ). The current implementation of MCDMfJ Table 1: three tools
recognizes all the GoF creational patterns. Tools
MCDMfJ is implemented as a GUI tool, with an FUJA
Pattern MCDMfJ PINOT HEDGEHOG
embedded pattern analysis engine. There are number of BA
advantages of using a compiler as the basis of a pattern Abstract
detection tool. A compiler constructs symbol tables and AST Y Y Y N
Factory
that facilitate the inter-class and static behavioral analyses. Builder Y - - -
Compilers also perform some semantic checks that help Factory
pattern analysis. Most importantly, compilation errors Y Y Y N
Method
reflect the incompleteness of symbol tables and AST, which Prototype Y - N -
result in incorrect pattern detection results. However, some
Singleton Y Y Y Y
tools, such as FUJABA and PTIDEJ, are able to partially
Y the tool claims to recognize the pattern and is able to
(with a fuzzy number) detect patterns from incomplete identify it in the AJP example
source. Such tools can be desirable if pattern detection is N the tool claims to identify this pattern but fails to identify
used as part of software forward-engineering, such as in AJP
building and incorporating patterns on the run. In our case, - tool excludes recognition for this pattern.
pattern detection is reserved for reverse- engineering, where
accuracy is vital. FUJABA has a rich GUI for software re-engineering. Its
MCDMfJ begins its detection process for a given pattern inference engine provides a UML-like visual
pattern based on what is most likely to be most effective in language for user-defined patterns. The language allows
identifying that pattern (i.e., declarations, associations, or specifying inter-class relationships and a “creates”
delegations). This reduces the search space by pruning the relationship (which is the same as the “instantiates”
least likely classes or methods. The completeness of a predicate defined in SPINE). FUJABA is easy to use: the
pattern detection tool is determined by the ability of user simply specifies the location of the source code and
recognizing pattern implementation variants. For practical then runs the pattern inference engine. FUJABA displays
reasons, MCDMfJ focuses on detecting common the results graphically. FUJABA can run entirely
implementation variants used in practice. Thus, some automatically or incorporate interactive user guidance to
behavioral analysis techniques are not fully applied to each reduce its search space. PINOT is fully automated; it takes a
behavior-driven pattern. As an example, data-flow analysis source package and detects the pattern instances. All
is applied to analyzing the activities of the flag variable that detection algorithms are currently hard-coded to prove the
guards the lazy instantiation in the Singleton pattern. The correctness of our techniques on the structure- and behavior-
flag can have any data type, but java.lang.Object (when the driven patterns.
14 (IJCNS) International Journal of Computer and Network Security,
Vol. 2, No. 1, January 2010
Although these three tools were built for different uses, [10] J. Fabry and T. Mens. Language Independent Detection
they all involve pattern recognition. Thus, we compare these of Object-oriented Design Patterns. Computer
tools in terms of accuracy. Table 1 shows the results of Languages, February 2004.
testing each tool against the demo source from “Applied [11] G.Antonoil, R. Fiutem, and L.Cristoforetti. Design pat-
Java Patterns”(AJP) [3]. Each AJP pattern example is tern recovery in object-oriented software. In Proc. Of
similar to the one illustrated in the GoF book [6]. Thus, the 6th International Workshop on program
MCDMfJ tests a class against all pattern definitions. Comprehension, pg.’s 153-160. IEEE Computer
FUJABA was also tested in the same fashion. HEDGEHOG, Society Press, June 1998.
however, is not an automated verification tool and users are [12] J. Paakkii, A. Karhinen, J. Gustafsson, L.Nenonen, and
responsible of picking the patterns to verify against the A.I Verkamo. Software metrics by architectural pattern
target class. Thus, HEDGEHOG’s results shown in Table 1 mining. In Proc. Of the International Conference on
were based on prior knowledge of the source and only likely Software Theory and Practice, pg.’s 325-332. 16th IFIP
patterns were verified against a class [4]. World Computer Congress, August 2000.
[13] M. Vok´aˇc. An efficient tool for recovering design patterns
Future Work from C++ code. Journal of Object Technology,5(2), March-
April 2006.
[14] R. Keller, R. Shauer, S. Robitaille, and P. Pag´e. Pattern-
The future work with MCDMfJ will : expand its pattern based reverse-engineering of design components. In Proc. Of
identification capability to recognize more complicated user- the 21st International Conference on Software Engineering,
defined data structures; experiments with its use in tracking pg.’s 226-235. IEEE Computer Society Press. May 2002.
software evolution by design; and its overall usability by [15] J. Bansiya. Automating design pattern identification -
providing a visual specification language for defining DP++ is a tool for C++ programs. Dr. Dobbs
patterns and exporting our analysis results as XML for Journal,1998.
external viewing. [16] A.Asenico, S. Cardman, D.Harris, and E. Laderman.
Relating expectationsto automatically recovered design
References patterns. In WCRE, pg.’s 87-96,2002.
[17] Gue´he´neuc and G. Antonoil “ DEMIMA: A Multi-
[1] Nija Shi and Ronald A. Olsson, “ Reverse Engineering layered approach for Design Pattern Identification.
of Design Patterns from Java Source Code”. 21st IEEE Transactions on Software Engineering. Sep/Oct.
IEEE/ACM International Conference on Automated 2008.
Software Engineering, August 2006.
[2] Z.Balanyi and R. Ferenc. “Mining Design Patterns
Authors Profile
form C++ Source code”. In Proc. Of International
Conference On Software Maintainence. Praneeth Kumar G received the B.Tech
[3] Stephen Stelting and Olav Maassen, Applied Java degree in Computer Science And
Patterns, Prenctie Hall PTR. Engineering from Progressive Engineering
[4] Alex Blewitt, Alan Bundy and Ian Stark “Automatic College in 2008 . During May 2008-August
Verification Of Java Design Patterns,” In Proc. of the 2009, he worked in Concepts Of
16th annual conference on Automated Software Computing(CIC) as a Software Engineer.
Engineering. Nov. 2001 Pg.’s 324-327 Now he is working with Medha College Of
Engineering as an Assistant Professor. His
[5] Pattern Stories : Java AWT. http://wiki.cs. uiuc.edu
area of interests include software
/PatternStories/JavaAWT engineering, Information Security.
[6] E. Gamma, R Helm, R Johnson, and J. Vlissides.
Design Patterns : Elements of Reusable Object –
Oriented Software. Addison – Wesley, Aditya Kumar K received the B.Tech
Reading,Masachussets,1995. degree in Information Technology from
[7] J. Niere, W. Shafer, J.P. Wadsack, L. Wendehals, and Aurora Engineering College in 2008 .
J.Welsh Towards Pattern Based Design Recovery. In During May 2008-August 2009, he worked
ICSE, pg.’s 338-348. IEEE Computer Society Press, in Concepts Of Computing(CIC) as a
May 2002. Software Engineer. Now he is working with
[8] J. Seemann and J. W. von Gudenberg. Pattern-based Krishna Murthy Institute Of Engineering
and Technology as an Assistant Professor.
design recovery of Java software. In Proc. of the 6th
His area of interests include software
ACM SIGSOFT International Symposium on engineering, Information Security.
Foundations of Soft-ware Engineering, pg.’s 10-16.
ACM Press,1998
[9] J.M.Smith and D.Stotts. SPQR : flexible automated
design pattern extraction from source code. In ASE,
pg.’s 215-224. IEEE Computer Society Press, October
2003.

You might also like