Upload
julian-parks
View
218
Download
0
Embed Size (px)
DESCRIPTION
Observer pattern using an aspect A simple figure editor Invoke when updated
Citation preview
AspectScope: An Outline Viewer for AspectJ Programs
Michihiro Horie, Shigeru ChibaTokyo Institute of Technology, Japan
Aspect-Oriented Programming allows developers to combine a module to an
aspect without explicit method calls Logging, access authentication etc.
Problem: Difficult to understand relationships between
classes and aspects Must understand a whole system to understand
one class
Observer pattern using an aspect A simple figure editor
Invoke when updated
Observer pattern in AspectJ When the setX method and the setY method in
Point and the moveBy method in Shape are called, the advice body is executed.
aspect DisplayUpdate { pointcut change() : call(void Point.setX(int)) || call(void Point.setY(int)) || call(void Shape+.moveBy(int,int));
after() returning : change() { Display.update(); // an advice body }}
Refactoring: Let’s use accessors Stop directly accessing the fields in Point. Use accessors.
public void moveBy(int dx, int dy) { p1.x += dx; p1.y += dy; p2.x += dx; p2.y += dy;}
public void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); p1.setY(p1.getY() + dy); p2.setX(p2.getX() + dx); p2.setY(p2.getY() + dy); }
Five display updates
This refactoring causes display flickers.
The DisplayUpdate aspect is executed at five points. a call to the moveBy calls to the setters
public void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); p1.setY(p1.getY() + dy); p2.setX(p2.getX() + dx); p2.setY(p2.getY() + dy); }
Criticism In AOP, modular reasoning is difficult.
No indication of the aspectin the implementation of moveBy
Whole program analysis is needed. To understand the program behavior,
we must investigate all the aspects and classes.
public void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); p1.setY(p1.getY() + dy); p2.setX(p2.getX() + dx); p2.setY(p2.getY() + dy); }
No indication at the source level
AspectScope enables to find all the five join points
By only looking at module interfaces An Eclipse plugin for AspectJ
two panels: the outline view and the javadoc pane
Outline view Javadoc pane
The outline view of AspectScope
lists methods and fields declared in a given class It shows an arrow icon
if the method/field is advised by an aspect.
extende by the DisplayUpdate aspect
Shows the spec. of module interfaces
The javadoc pane of AspectScope
It displays the javadoc comments of a selected member, such as a method or a field Shows the comments taken from an aspect
if the member is advised by the aspect.
• From the pointcut definition
• From the advice definition
• From the implementation of setX()
• An English translation of the pointcut
Shows the comments on module interfaces
setX
Why does AspectScope… show join point indicators
in the view of module interfaces?
Because developers will look at the module interfaces
When they are doing modular programming.
What does the developer look at when they are refactoring the figure editor?
An experienced developer will…
First, check the module interfaces of: 1. moveBy in Line2. the setX and the setY in Point
because she will change moveBy to use setX and setY.
Then, edit the body of moveBy.
public void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); p1.setY(p1.getY() + dy); :}
moveBy …….………………setX ……..……………setY ……..……………
So, show arrow icons…
In the view of the module interfaces of: the moveBy in Line the setX and the setY in Point
On the source code editor
You can also see this module interfaceon the source code editor.
Easy to find all the five join points
By only looking at the module interfaces of moveBy, setX and setY.
public void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); p1.setY(p1.getY() + dy); p2.setX(p2.getX() + dx); p2.setY(p2.getY() + dy);}
moveBy ………….…….extrended by DisplayUpdate
setX …………....…….extended byDisplayUpdate
setY ……..………..extended byDisplayUpdate
AJDT does not show there! It shows arrow icons in the source editor
The source code at the caller site if the pointcut is call
pointcut change() : call(void Point.setX(int)) || call(void Point.setY(int)) || call(void Shape+.moveBy(int,int));
The 4 of 5 join points areindicated here.
AJDT editor
Problem
Where is the missing join point?
It is in the source code of another class! The caller/client method The developer must look at that as well.
If there is no aspect, they would not look at them. This is far from modular programming.
caller (client)
callee (target)
Call pointcut in AJDT(also get & set pointcut) An arrow icons is shown in the Rect class.
Rect is the caller class
class Rect { : line.moveBy(dx, dy); :} caller
class Line { : void moveBy(int dx, int dy){ :}} callee
aspect DisplayUpdate { : after(): call(void Line.moveBy(..)) { Display.update(); }}
Never seewhen refactoringmoveBy!
Call pointcut in AspectScope(also get & set pointcut) An arrow icon is shown in the Line class.
Line is the callee classaspect DisplayUpdate { : after(): call(void Line.moveBy(..)) { Display.update(); }}class Rect {
: line.moveBy(dx, dy); :} caller
class Line { : void moveBy(int dx, int dy){ :}} callee
An essential difference in the abstraction AspectScope
Outline view (module interfaces). Developers will look at module interfaces when refactoring.
Effects of aspects are always shown at the callee site.
AJDT Source code editor
Developers must look at the body of the caller methods as well as callee ones.
Effects of aspects may shown at the caller site.
Or, the source editor at the callee site
The revised DisplayUpdate
So the developer will be able to write the correct aspect.
The update method is invoked only when the setX, setY, and moveBy method is called as a top-level call. No need to modify on the moveBy method itself
after() returning : change() && !cflowbelow(change()) { Display.update(); }
Related Work Aspect-Aware Interface [Kiczales et al. 2005]
It shares basic ideas with AspectScope. Conceptual framework for modular reasoning.
These paper does not mention call, get, and set pointcuts. No javadoc comments. AspectScope is a tool based on the AAI idea.
Classbox/J [Bergel et al. 2005] Similar to the interpretation of aspects by AspectScop
e. Enables an extension only effective to a particular mo
dule.
Conclusion AspectScope:
A programming tool for AspectJ An outline viewer of a class It shows the outline of a class woven with an aspect
Declared methods and fields javadoc comments for the methods and fields extended by a
spects Shows arrow icons where developers will look.
It enables modular reasoning