Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
Fig. 3
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.
Fig. 6
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.
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.