Design Pattern Implementation in Java and AspectJ - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Design Pattern Implementation in Java and AspectJ

Description:

GoF(Gang Of Four) Design Patterns. E. Gamma, R. Helm, R Johnson, J. Vlissides ... Conveys the essence of a proven solution to a recurring problem ... – PowerPoint PPT presentation

Number of Views:398
Avg rating:3.0/5.0
Slides: 21
Provided by: salmosa
Category:

less

Transcript and Presenter's Notes

Title: Design Pattern Implementation in Java and AspectJ


1
Design Pattern Implementation in Java and AspectJ
  • Jan Hannemann, Gregor Kiczales
  • OOPSA 2002

2003. 5. 27 Presented by Cheolho Kim
2
Contents
  • Introduction
  • Experiment Format
  • Result 1 Observer Pattern
  • Result 2 Other Patterns
  • Analysis
  • Related Work
  • Conclusion

2/18
3
Introduction(1/3)
  • GoF(Gang Of Four) Design Patterns
  • E. Gamma, R. Helm, R Johnson, J. Vlissides
  • Collected 23 design patterns
  • Conveys the essence of a proven solution to a
    recurring problem
  • Regarded as useful solution to certain type of
    design problems

3/18
4
Introduction(2/3)
  • Three most important challenges of patterns
  • disappearing into the code problem
  • This make it hard to distinguish between the
    pattern and the object model involved
  • Documentation problem
  • Because of invasive nature of pattern code, it is
    difficult to trace a particular instance if
    multiple patterns are used
  • Pattern composition problem
  • It is difficult to reason about systems with
    multiple patterns involving the same classes

4/18
5
Introduction(3/3)
  • Initial experiment to develop and compare Java
    and AspectJ implementations of the GoF patterns
  • Crosscutting structure between roles and
    participant classes exists
  • Modularizing the crosscutting structure improves
    the implementation of patterns
  • 17 of 23 patterns implemented in AspectJ are
    improved in reusability, composability and
    (un)pluggability

5/18
6
Experiment Format
  • Comparative analysis of Java and AspectJ
    implementation of the GoF design patterns
  • Java implementations corresponds to the sample
    C implementation in the GoF book
  • AspectJ implementations are selected among 57
    different implementations to fully investigate
    the design space of each pattern

6/18
7
Result 1 Observer Pattern(1/4)
  • What is observer pattern?

The Observer pattern describes how to establish
these relationships - Subject may have any number
of dependent observers. - All observers are
notified whenever the subject undergoes a change
in state. - Each observer will query the subject
to synchronize its state with the subject's state.
7/18
8
Result 1 Observer Pattern(2/4)
  • Implementation in Java

1. Code for implementation is spread across the
classes 2. All participants have to know about
their role in the pattern
  • Changes requires modification in all
    participating classes
  • adding or removing a role
  • using alternative notification mechanism

8/18
9
Result 1 Observer Pattern(3/4)
  • Implementation in AspectJ

Specific parts to each instantiation
1. Give each role to a class 2. Set of changes of
interest on the Subject 3. Means of updating each
Observer
Concrete subaspect
Abstract aspect
9/18
10
Result 1 Observer Pattern(3/4)
Abstract aspect
  • Implementation in AspectJ

11
Result 1 Observer Pattern(3/4)
  • Implementation in AspectJ

9/18
12
Result 1 Observer Pattern(4/4)
  • Improved properties of implementation in AspectJ
  • Locality
  • All the code that implements the pattern is in
    the abstract and concrete aspects
  • No coupling between the participant classes
    exists
  • Reusability
  • Core pattern code(ObserverProtocol) is abstracted
    and reusable
  • For each pattern instance, only define one
    concrete aspect
  • Composition transparency
  • Even if a class takes part in multiple observing
    relationships, codes of the class and pattern are
    not confused
  • (Un)pluggability
  • Participants need not be aware of their role
  • It is easy to switch between using a pattern or
    not using it

10/18
13
Result 2 Other Patterns
  • Composite, command, mediator, chain of
    responsibility
  • Roles only used within pattern aspect
  • Singleton, prototype, memento, iterator,
    flyweight
  • Aspects as object factories
  • Adapter, decorator, strategy, visitor, proxy
  • Language constructs
  • Abstract factory, factory method, template
    method, builder, bridge
  • Multiple inheritance
  • State, interpreter
  • Parts of scattered code can be modularized
  • Façade
  • No benefit from AspectJ

11/18
14
Analysis (1/4)
  • Analysis is broken into three parts
  • General improvements observed in many pattern
    re-implementation
  • Specific improvements associated with particular
    patterns
  • Origins of crosscutting structure in patterns
  • Observed improvements correlate with the presence
    of crosscutting structure

12/18
15
Analysis (2/4)
  • General improvements
  • Locality
  • 17 of 23 GoF patterns
  • All dependencies between patterns and
    participants are localized in the pattern code
  • Reusability
  • 12 of 17 localized patterns
  • By separating pattern-specific code, participant
    and pattern can be reusable in other contexts
  • Transparent composability
  • 14 of 17 localized patterns
  • A class or object can have different roles in
    different pattern instances without confusion
  • (Un)pluggability
  • Reusability and adaptability of patterns

13/18
16
Analysis (3/4)
  • Specific improvements
  • Singleton case
  • AspectJ provides design choices
  • Singleton property is implemented as inherited
  • Constructor instead of a devoted factory method
    can be used
  • Multiple inheritance and Java
  • AspectJ provides a way of implementing patterns
    having multiple-inheritance with transparent
    composability
  • Breaking cyclic dependencies

14/18
17
Analysis (4/4)
  • Crosscutting structure of design patterns
  • Crosscutting in pattern structure is caused by
    different kinds of roles and their interaction
    with participants
  • Roles
  • Defining roles - define the participants
    completely
  • Superimposed roles - assigned to classes
  • Roles crosscut participant classes
  • Conceptual operations of interest crosscut
    methods
  • Roles from multiple patterns crosscut each other

15/18
18
Related Work (1/2)
  • Design patterns and language paradigms
  • Investigation of pattern applicability in other
    language paradigm
  • Pattern libraries and tool support
  • Automation of design and code generation
  • Pattern classification
  • Classifying existing patterns in order to reduce
    the number of distinct patterns or to pinpoint
    relationships

16/18
19
Related Work (2/2)
  • Roles and pattern composition
  • Approaches to model roles and their relationship
    to the concrete classes playing those roles
  • Alternative pattern representations
  • Approaches to design pattern notation

17/18
20
Conclusion
  • Improvement from using AspectJ manifest
    themselves as a set of properties related to
    modularity
  • Reusability, composition transparency,
    (un)pluggability
  • Improvement is directly correlated to the
    presence of crosscutting structure in the
    patterns
  • Future work
  • Applying AspectJ to other patterns
  • Comparing the results with the use of other AOP
    techniques

18/18
Write a Comment
User Comments (0)
About PowerShow.com