Sei sulla pagina 1di 4

A Novel Approach for Dynamically Recognizing Strategy Design Pattern in Java

Kurimilla Sridhar Nuthi Sudhakar Jayadev Gyani


Dept. of Comp. Sci. Research Scholar. Dept. of Comp. Sci.
Vaagdevi P.G. College, Rayalaseema University, Jayamukhi Institute of
INDIA INDIA Technological Sciences
kurimilla@gmail.com nuthisudhakar@yahoo.com INDIA
jayadevgyani@yahoo.com

Abstract specific sequences of actions and interactions of the


Design patterns lead to production of high quality and objects of these classes [4](dynamic information).
easily maintainable software. Design pattern recognition
is usually realized by static analysis based on source Design pattern recognition is usually realized by static
code, suited for recognition of structural aspects but analysis based on source code, suited for recognition of
limited and imprecise in analyzing behavior. Design structural aspects but limited and imprecise in analyzing
patterns, however, usually comprise not only structural behavior .Design patterns, however, usually comprise not
but also significant dynamic aspects. In this paper we only structural but also significant behavioral aspects. An
present a novel approach for detecting strategy design example can be found in [6].
pattern using both static and dynamic analysis.
For precise design pattern recognition, such a static
Key Words: Dynamic aspects, static analysis, analysis is not sufficient. The behavioral aspects of a
dynamic analysis. pattern are an important factor. Dynamic analyses can be
used to analyze the runtime behavior of a system.

1. Introduction 2. Previous Work


Design patterns are generally defined as descriptions Previously the structure and the behavior of the system
of communicating classes that form a common solution to with respect to the patterns indicating the instance of a
a common design problem. They have widely and rapidly certain design pattern .This is necessary, since there are
attracted the interest of the software engineering situations, where neither static nor dynamic analyses
community. Their proponents argue that their use leads to alone are sufficient (or not with acceptable expenses). For
the construction of well-structured, maintainable, and example it is statically not computable, which method or
reusable software systems. Because most current software attribute is actually called or accessed at run time and how
projects deal with evolving products consisting of a large often. Even data flow analyses cannot predict when the
number of components, their architecture can become program to be analyzed requires user interactions. As
complicated and quite messy. Design patterns can impose objects are created at run time, relations among objects
structure on the system due to the abstractions being used. are dynamic by nature.
Consequently, the identification of implemented design
patterns could be useful for the comprehension of an
existing design and provides the ground for further
improvements.
Extraction of design patterns further enables in
3. Present work
applying behavior-preserving transformations to improve Recognition of Design Pattern using Dynamic
design , readability and maintainability of exiting code Analysis:
[2], [3].
A tool-based recognition is defined for each design
pattern. The process starts with static analysis which takes
Design patterns usually have static and dynamic
source code of the system (cf. Fig 3).and is passed for
aspects. A pattern specifies structural Connections among
dynamic analysis to check for each design pattern
the classes via call, delegation or inheritance relations
candidate if the collaboration of its constituents at runtime
(static information). Additionally, it requires some
conforms to the behavioral description of the design
pattern. The design pattern candidates and behavioral
pattern specifications are used to record method call traces
during the program’s execution[7]. Only those classes and
methods are monitored during dynamic analysis that have
been identified by static analysis. This reduces the amount
of gathered data significantly. The program is executed
manually by the reverse engineering.

Strategy pattern
The Strategy pattern is useful for situations where it is
necessary to dynamically swap the algorithms used in
application. The strategy pattern is intended to provide a Fig.2
means to define a family of algorithms, encapsulate each
one as an object, and make them interchangeable. The We propose to identify the design pattern (strategy)[5]by
strategy pattern lets the algorithms vary independently analyzing the structure and the behavior of the system
from clients that use them. with respect to the patterns indicating the instance of a
certain design pattern. Here we trace the pattern at run
The strategy pattern uses composition instead of time by user interaction with acceptable values to identify
inheritance. In the strategy pattern behaviors are defined which method is called with what attribute values. Only
as separate interfaces and specific classes that implement those classes and methods are monitored during dynamic
these interfaces. Specific classes encapsulate these analysis that has been identified by static analysis. This
interfaces. This allows better decoupling between the reduces the amount of gathered data significantly. The
behavior and the class that uses the behavior. The program is executed manually by the reverse
behavior can be changed without breaking the classes that engineering[1].
use it, and the classes can switch between behaviors by
changing the specific implementation used without
requiring any significant code changes. Behaviors can also Source Executable
be changed at runtime as well as at design-time. code program

Static Dynamic Identified


Analysis analysis pattern

Fig. 3

Here we try to identify Strategy pattern by selecting a


class .Probability that a selected class will be a candidate
class for strategy pattern is that it is a context class.

Algorithm

1. Load a class.
2. Analyze for interface handles.
UML Diagram (Fig. 1) 3. Identify the interface class.
4. Look for concrete classes that implement interface.
5. Dynamic building of client class for request
invocation.
6. Execution of the class and displaying the results.
4. Implementation decide what algorithm implementation we need to invoke
at runtime. For executing the method dynamically a class
For implementation purposes an instance of strategy is built with the type of object that is to pass (Fig. 5) and
pattern need to have the following with type of parameters to be passed to the execute
method.
1. Context class
2. Strategy Interface
3. Concrete Strategy interface implemented classes.

The above classes are used in static analysis of the


design pattern.

4. Virtual Machine class.


5. Event Queue class.
6. Event Set Class.

Are used for observing the dynamic behavior of the Fig. 5


design pattern.
The parameters are drawn from the keyboard (fig. 6)
Here we consider an example as shown in Fig.4. and the test class is built. the test class is executed by
Where there is an interface called Strategy with abstract selecting exec test class.
method called execute with two integer parameters and
return value of integer type. this method has different
algorithmic implementation depending on the type of
concrete class selected as the concrete classes implements
the Strategy interface.
The Context class has a handle of Strategy interface
(Composition) which can hold any of its subclass objects
and invoking the Strategy method will result in the
execution of the subclass algorithm.
The Context constructor has Strategy interface as
parameter while creating the object for Context class any
of the subclass objects of the Strategy interface can be
passed and that can be assigned to the Strategy interface
handle declared within the class.

Fig. 6

The results are displayed showing (Fig. 7) which


method of the Context class called the interface handle
execute method and which algorithm is executed with
results displayed.

5. Conclusion
In this paper we reported a contribution to area of
reverse engineering by using a novel detection technique.
Fig. 4
Momentarily our tool supports only a limited no of design
patterns. We proposed flexible design pattern detection
When a Context class is loaded the tool searches for the
process. And also, we created a detection algorithm for
Strategy interface handle and the interface is displayed
each design pattern. We are trying to improve this tool kit
(Fig. 5) along with the names of the concrete classes that
so that can detect many different design patterns.
implement the interface. Selecting the subclass type will
[4] L.Wendehals. “Improving Design pattern Instance
Recognition by Dynamic Analysis” .Proc. of the ICSE
2003 Workshop on Dynamic Analysis, 2003.

[5] “A Design Pattern Detection Technique that Aids


Reverse Engineering”.Hakjin Lee,Hyunsang Youn,
Eunseok Lee.

[6] L. Wendehals. Specifying Patterns for Dynamic


Pattern Instance Recognition with UML 2.0 Sequence
Diagrams. In E.-E. Doberkat and U. Kelter, editors, Proc.
of the 6th Workshop Software Reengineering (WSR), Bad
Honnef, Germany, Softwaretechnik-Trends, volume 24/2,
pages 63–64, May 2004.

[7] L. Wendehals, M. Meyer, and A. Elsner. Selective


Tracing of Java Programs. In A. Sch¨urr andA. Z¨undorf,
Fig.7 editors, Proc. of the 2nd International Fujaba Days 2004,
Darmstadt, Germany, volumetr-ri-04-253 of Technical
Reports, pages 7–10. University of Paderborn, September
2004.
6. Future Work
Both static and dynamic analyses produce fuzzy rated
results. The results from dynamic analysis can be used to
automatically calibrate the credibility values of the static
analysis rules.
A possibility to extend the presented approach is to
monitor object attributes. Constraints on the attribute values
can be defined within states in the behavioral patterns. Value
changes of attributes used in those constraints can be
recorded and the constraints will be checked during pattern
recognition.

7. References.
[1] .N. Shi, and R. Olsson. “Reverse Engineering of
Design Patterns from Java Source Code”, The 21st!
EEE/ACM International Conference on Automated
Software Engineering, 2006.

[2] Jayadev Gyani and P.R.K.


Murti,"Enhancing Software Evolution with Pattern
Oriented Software Product Life Cycle", pre-
conference proceedings of IEEE conference on
Software Technology and Engineering Practice
(STEP-2005),Budapest, Hungary

[3] N. Sudhakar and J. Gyani, “Tecdp: A Tool for


Extracting Creational Design Patterns”, in
Proceedings of ACM International Conference and
Workshop on Emerging Trends in Technology, 2010,
pp. 735-736.

Potrebbero piacerti anche