FYI: AspectJ (Was: [Biojava-l] Immutable Features)

Vladimir G Ivanovic vladimir@acm.org
Thu, 13 Dec 2001 08:55:33 -0800


"TD" == Thomas Down <td2@sanger.ac.uk> writes:

  TD> A few people have asked recently about features implementing
  TD> multiple Feature interfaces. In principle there's no reason not to
  TD> (especially if we use code similar to the current ProjectionEngine
  TD> system to dynamically generate the actual objects :-), but the
  TD> current Feature.Template system breaks, because you can't
  TD> multiple-inherit the classes.

AspectJ (http://aspectj.org) allows you to multiply inherit, provided
there are no naming conflicts. AspectJ produces either Java bytecode or
optionally Java source which you can then compile with your favorite
Java compiler.

But this is just one feature of AspectJ. Its purpose in life is to
implement "crosscutting concerns". Crosscutting concerns are issues,
concerns, attributes, or features of classes that are not easily or
naturally factored into classes. The crosscut the notion of classes.

Take the simplest example (ignoring the fact that it's now present in
Java 1.4): logging. Rather than having to add logging calls everywhere,
and then changing them everywhere when the logging method's signature
changes, it's easier to describe programmatically the places where
logging should be done and let the compiler add them. 

AspectJ adds to Java the notion of a pointcut, a well-defined,
restricted set of points in the execution of a Java program, and advice,
code that is run when a pointcut is reached. Advice looks like an
ordinary Java method, and can be run before, after, or before and after
a pointcut is reached. AspectJ also allows you to modify the class
hierarchy and the static structure of your classes, by intorducing
members to existing classes, and by introducing inheritance where none
existed before.

Pointcuts, advice and introductions are all wrapped in a aspect, a
new language construct that looks suspiciously like a class.

There are several styles of using AspectJ. The most conservative style
allows you to yank all AspectJ related stuff out of your final build,
but still benefit from using aspects during the development process.
(It's great for debugging and testing.)

The current release is v1.0 which is intended for production use.
AspectJ is integrated with GNU Emacs/XEmacs, Forte for Java and
JBuilder. The AspectJ compiler is written in Java, so it runs on any
Java platform. 

--- Vladimir

Disclaimer: I used to produce documentation for the AspectJ project at
Xerox PARC, but I currently have no connection with AspectJ or PARC.

---------
Vladimir G. Ivanovic                        http://leonora.org/~vladimir
2770 Cowper St.                                         vladimir@acm.org
Palo Alto, CA 94306-2447                                 +1 650 678 8014