Information Technology Reference
In-Depth Information
aspect SimpleTracing {
pointcut traced() :
call(void Display.update()) ||
call(void Display.repaint(..));
before(): traced() {
println( "Entering: " + thisJoinPoint);
}
void println(String s) {
// write message
}
}
Figure 3.2.
AspectJ SimpleTracing Example.
Before advice - runs at the moment a join point is reached.
After advice - runs after the join point has been reached.
Around advice - runs when the join point is reached and has explicit control
over whether the method is run or not.
An advice is declared using one of the advice keywords. For example, the following
advice prints a message after the weAreMoving method is called using the after
keyword:
after(): weAreMoving() {
System.out.println( "We have moved" );
}
Aspects wrap up pointcuts, advice, and inter-type declarations in a modular
unit of crosscutting implementation and is defined similar to a class. Inter-type
declarations are members of an aspect (fields, members and constructors) that are
owned by other types, and aspects can also declare that other types implement
new interfaces or extend a new class [6].
Aspects can contain methods, fields, and initialisers in addition to the cross-
cutting members. The following is an example of a simple aspect that is used to
print messages before certain display operations:
As can be seen from the example in Figure 3.2, aspects in AspectJ are not
reusable because the context on which an aspect needs to be deployed is specified
directly in the aspect definition - the pointcut is part of the aspect [106]. Although
AspectJ allows aspects to be inherited from other aspects, it is only allowed if the
inherited aspect has been declared as abstract . Concrete aspects are therefore not
reusable. In addition, any change to a class may result in the necessity to alter
the aspect as the pointcut definition may no longer be valid.
Recognising this limitation, a number of researchers have been focusing on re-
moving the join point interception model from the aspect implementation. Lieber-
herr et al. [64] have developed the concept of Aspectual Components, which
Search WWH ::




Custom Search