opus group les | di |puc-rio - brazil alessandro cavalcante gurgel composing design patterns in...
TRANSCRIPT
OPUS Group
LES | DI |PUC-Rio - Brazil
http://www.les.inf.puc-rio.br/opus
Alessandro Cavalcante Gurgel
Composing Design Patterns in CaesarJ: An Exploratory Study
Agenda
Introduction Previous Studies
Background CaesarJ AspectJ
Case study Design of compositions Related Works Conclusions Future Works
Apr 21, 2023 Francisco Dantas et. al @ OPUS Group 2
Introduction
GoF Design Patterns are scattered and tangled in the base code.
Design Patterns Compositions. Sharing: methods, attributes and classes.
Modularity Problems Special scenario for analysing both strengths
and limitations of the languages .
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 3
Introduction – Previous Studies
Aspectising Design Patterns Hannemann,J., Kiczales,G. “Design Pattern Implementation in Java and
AspectJ”. Proc. OOPSLA’02, Nov 2002. Garcia, Sant’Anna, Figueiredo, Kulesza, Lucena. “Modularizing Design
Patterns with Aspects: A Quantitative Study.” 4th Intl. Conf. on Aspect-Oriented Software Development (AOSD'05). 2005
Cacho, Sant’Anna, Figueiredo, Garcia, Batista, Lucena “Composing Design Patterns: A Scalability Study of Aspect-Oriented Programming.” 5th Intl. Conf. on Aspect-Oriented Software Development (AOSD'06). 2006
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 4
Introduction – Previous Studies
Aspectising Design Patterns Hannemann,J., Kiczales,G. Design Pattern Implementation in Java and
AspectJ. Proc. OOPSLA’02, Nov 2002. Garcia, Sant’Anna, Figueiredo, Kulesza, Lucena. “Modularizing Design
Patterns with Aspects: A Quantitative Study.” 4th Intl. Conf. on Aspect-Oriented Software Development (AOSD'05). 2005
Cacho, Sant’Anna, Figueiredo, Garcia, Batista, Lucena “Composing Design Patterns: A Scalability Study of Aspect-Oriented Programming.” 5th Intl. Conf. on Aspect-Oriented Software Development (AOSD'06). 2006
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 5
The use of AspectJ in some compositions were problematic.
General Goals
Propose CaesarJ solutions that resolve or minimize emerging problems from compositions of Design Patterns.
Compare qualitatively AO, OO and CaesarJ solutions
Strengths and limitations of the languages
18 June Alessandro Gurgel et. al @ OPUS Group 6
What kind of problems ? Coupling, application restrictions, type-safe operations Quality solution improvements
Preserving the original solution of each design pattern.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 7
Why CaesarJ ?
Support to AOP and FOP (collaborations and refinements)
Stable compiler Applications of different domains Extension of Java Tutorials, examples and support of developers
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 8
Background - CaesarJ
Collaboration Interfaces Abstractions beetween components
Virtual Classes Inner classes, Overriden and late bound (virtual methods)
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 9
Running Example - Observer
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 10
Running Example - Observer
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 11
abstract public cclass Subject
Implicit Scoping!
Family
Aspects and Wrappers - CaesarJ Aspects
Classes that have pointcuts and advices References to aspects can be polymorphic Static , dynamic and instance level deployment
Wrappers Bindings map between types from two domains by means of
wrapper classes. Wrapper-wrappee relationship. Created on demand Reused for the same object Garbage collector
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 12
Running Example - Observer
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 13
Running Example - Observer
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 14
Mixin Composition
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 15
public cclass CO extends ObserverProtocolImpl & ColorObserver { }
Background - AspectJ Per-object aspects
aspect Id perthis(Pointcut) { ... } aspect Id pertarget(Pointcut) { ... } one object of type A is created for every this/tatget object at
any of the join points picked out by Pointcut The advice defined in A will run only at a join point where
the this/target object has been associated with an instance of A
A.aspectOf(Object) aspect Id pertypewithin(org.xyz..*) percflow and percflowbelow
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 16
Case Study - OpenOrb
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 17
Reflective middleware GoF patterns are used and combined to satisfy
the middleware modularity-related requirements
OO and AO solutions are available.
Open-Orb
Apr 21, 2023 Francisco Dantas et. al @ OPUS Group 18
Chosen Compositions – Representative Compositions
Strategy and Proxy Memento and Observer Decorator and State Decorator and Template Method. Mediator and Proxy Composite and Visitor Prototype and State.
18 de Maio Alessandro Gurgel et. al @ OPUS Group 19
Chosen Compositions – Problematic AspectJ solutions
Strategy and Proxy Memento and Observer Decorator and State Decorator and Template Method. Mediator and Proxy Composite and Visitor Prototype and State.
18 de Maio Alessandro Gurgel et. al @ OPUS Group 20
Design of the compositions
Composite and Visitor
18 de Maio Alessandro Gurgel et. al @ OPUS Group 21
Intent of each design pattern
Visitor Represents an operation to be performed on the
elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates
Composite Compose objects into tree structures to represent
part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 22
OO: Composite and Visitor
Apr 21, 2023 Alessandro Gurgel. al @ OPUS Group 23
Composite
Visitor
AO Solution CompositeProtocol
Componente, Leaf and Composite Interface for visiting operations
VisitorProtocol Leaf and Node
Problems Attribute Overlapping (aspectOf) Composite code in visit operations Non type safe visit methods
Intertype declaration Type-cast
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 24
HK
CaesarJ Solution I
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 25
Dynamic WrapperSelection
Discussions about the solution I
Visitor relates with the Composite pattern by the use of wrapper relations instead of AspectOf().
The visit methods do not need to typecast its argument. It uses the respective wrapper class as argument.
Dynamic Wrapper Selection - different cclasses that have the same name but wraps different classes from a common hierarchy to provide polymorphic behaviour according the wrappee object.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 26
This mechanism is not implemented yet.
Discussions about the solution I
Despite of being in the same family, the composite objects can be instatianted independently from the visitor structure.
Another option is to create a Family containing only the composite structure and then create a visitor family that extends the composite family
Apr 21, 2023 Alessandro Gurgel t. al @ OPUS Group 27
CaesarJ Solution II
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 28
•Extensibility with new operations •Extensibility with new data types.
The use of virtual classes promotes:
Creating new data types and operations
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 29
Discussions
Both solutions are in the same level of extensibility in terms of data type and operations since wrappers are also virtual classes.
In second solution, there is explicit code of composite in visit methods. In the third one, it is made by wrappee object.
Glue code – inheritance x binding
Apr 21, 2023 Alessandoro Gurgel et. al @ OPUS Group 30
Prototype and State
18 June Alessandro Gurgel et. al @ OPUS Group 31
Intent of each design pattern
Prototype Specifies the kinds of objects to create using a
prototypical instance, and creates new objects by copying this prototype.
State Allows an object to alter its behavior when its
internal state changes. The object will appear to change its class.
The pattern is also responsible for the state transitions (Context).
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 32
OO: Prototype and State
18 June Alessandro Gurgel et. al @ OPUS Group 33
Prototype
State
AO Solution
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 34
Problems of AO Solution PrototypeAspect.aspectOf().createCloneFor() Inter-aspect coupling. The natural dependencies between the business classes Declare-precedence related to other aspect that is not involved
in this composition (DecoratorAspect and StateAspect)
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 35
CaesarJ solution
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 36
Discussions
Concrete prototypes and concrete states are defined in a modular way.
The class ConcreteBind acts like the context role in state design pattern and the client in prototype.
Instead of having coupling between aspects, the ConcreteBind has variables that are states and also prototypes. The transition of bdState uses these variables in makeRequest method.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 37
Decorator and State
18 June Alessandro Gurgel et. al @ OPUS Group 38
Intent of each design pattern State
Allows an object to alter its behavior when its internal state changes. The object will appear to change its class.
The pattern is also responsible for the state transitions (Context).
Decorator Attach additional responsibilities to an object dynamically.
Decorators provide a flexible alternative to subclassing for extending functionality.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 39
OO: Decorator and State
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 40
State
Decorator
AO Solution
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 41
Problens of AO Solution
Since BindStateAspect and DecoratorAspect intercept the same joint point, an order of execution is established using declare precedence.
Using the DecoratorAspect there is no bound about which ConcreteBind objects will be decorated. One possible solution is to create a decorator class extending the ConcreteBind and only intercept the objects from that classes using target in the joint point designator.
perthis, pertarget do not address the problem since is not related to instances of aspects
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 42
CaesarJ Solution
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 43
The state design pattern remains the same
Deploy on object instance
Discussion
Using CaesarJ we can obtain the same benefits of AO solution and we also can limit the objects that are decorated by the entity DecoratorCJ using the deploy on object mechanism .
Another scenarios Mixin Composition Wrappers
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 44
Mediator and Proxy
18 June Alessandro Gurgel et. al @ OPUS Group 45
Intent of each design pattern
Mediator Defines an object that encapsulates how a set of
objects interact. Proxy
Provides a surrogate or placeholder for another object to control access to it.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 46
OO Mediator e Proxy
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 47
Mediator
Proxy
Each method invoke makeRequest from ConcreteBind
Problems and Solutions
Described by Cacho (2006): Central element in OpenOrb. Unique instance of Mediator Aspect Bottleneck in the invocation of the middleware
platform – Performance Extension of AspectJ - pertarget, perthis CaesarJ dynamic aspect deployment Multiple instances of ConcreteBind
attached to different proxy instancesApr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 48
Memento and Observer
18 June Alessandro Gurgel et. al @ OPUS Group 49
Intent of each design pattern
Memento Without violating encapsulation, capture and
externalize an object's internal state so that the object can be restored to this state later.
Observer Define a one-to-many dependency between objects
so that when one object changes state, all its dependents are notified and updated automatically.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 50
OO: Memento and Observer
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 51
Memento
Observer
AO Solution ObserverProtocol – abstract pointcut and infrastructure for
registration and notification of observers. ObserverAspect – defines the abstract pointcut that intercepts
changes in the subject. MementoProtocol – defines interface for originator and its
abstract methods. MementoAspect – uses ID to assignment application classes to
the originator role and implements its methods. Problems
The implementation of the originator methods in the MementoAspect is not type safe.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 52
CaesarJ Solution
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 53
Memento
Observer
Discussion
The use of CaesarJ bindings wrappers instead of intertype declaration we ensure secure type in originator methods.
Alternative Solution: Define Memento in each originator family Dependent typing can ensure that the object is
restored to its own memento objects only
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 54
Decorator and Template Method
18 June Alessandro Gurgel et. al @ OPUS Group 55
Intent of each design pattern
Decorator Attach additional responsibilities to an object
dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
Template Method Define the skeleton of an algorithm in an operation,
deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 56
OO Solution
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 57
Template MethodDecorator
Decorator
Template Method
Discussion
Both classes DecoratorBind and MetaBind are part of Template Method and Decorator.
The implementation of Template Method is entirely contained by the Decorator.
In this composition, we preserved the solution of Decorator that was described in its composition with State.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 58
Related Works Edgar Sousa , Miguel P. Monteiro, Implementing design
patterns in CaesarJ: an exploratory study, Proceedings of the 2008 AOSD workshop.
Martin Kuhlemann , Marko Rosenmüller , Sven Apel , Thomas Leich, On the duality of aspect-oriented and feature-oriented design patterns, Proceedings of the 6th workshop on Aspects, components, and patterns for infrastructure software, 2007, Vancouver, Canada
Marot, A. and Wuyts, R. 2010. Composing aspects with aspects. In Proceedings of the 9th international Conference on Aspect-Oriented Software Development (Rennes and Saint-Malo, France, March 15 - 19, 2010). AOSD '10. ACM, New York, NY, 157-168.
Apr 21, 2023 Alessandro Gurgel et. al @ OPUS Group 59
Conclusions
Inter-type Declarations x CaesarJ Bindings Reuse and Polymorphism x Glue Code Type-safe -> Dynamic Wrapper
Refactoring Process – Glue Code This paper presented strenghts and limitations
on both AspectJ and CaesarJ. CaesarJ – equals or better solutions.
Joint point model Dynamic, instance level deployment
Apr 21, 2023 Alessandro Gurrgel et. al @ OPUS Group 60
Future Works
Replicate the study in other systens from different domains.
Trying reuse the same solutions Comparing with new AOP languages like
Compose* Quantitative study
Metrics
Apr 21, 2023 Alessandro Gurrgel et. al @ OPUS Group 61