I want my AOP!, Part 2
Learn AspectJ to better understand aspect-oriented programming
By Ramnivas Laddad, JavaWorld.com, 03/01/02
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
In Part 1 of this three-part series on aspect-oriented programming (AOP), I introduced AOP concepts and briefly gave AOP implementation
examples. Continuing that trend in this article, I present a concrete AOP implementation for Java: AspectJ, a free implementation
and language specification from Xerox PARC. Moreover, I aim to impart familiarity with the AspectJ concepts you will need
for Part 3.
Read the whole "I Want My AOP" series:
In this article, I lean towards conciseness rather than completeness. For a comprehensive tutorial, I highly recommend the
AspectJ Group's official AspectJ Programming Guide.
Note: You can download this article's complete source code in Resources. The sample code works with AspectJ 1.0.3 -- the latest available version at the time of publication.
AspectJ overview
AspectJ is a language specification as well as an AOP language implementation. The language specification defines various
constructs and their semantics to support aspect-oriented concepts. The language implementation offers tools for compiling,
debugging, and documenting code.
AspectJ's language constructs extend the Java programming language, so every valid Java program is also a valid AspectJ program.
The AspectJ compiler produces class files that comply with Java byte code specification, enabling any compliant JVM to interpret
the produced class files. By choosing Java as the base language, AspectJ passes on all the benefits of Java and makes it easy
for Java programmers to use it.
AspectJ, as one of its strong points, features helpful tools. It provides an aspect weaver in the form of a compiler, an aspect-aware
debugger and documentation generator, and a standalone aspect browser to visualize how an advice crosscuts a system's parts.
Moreover, AspectJ offers good integration with popular IDEs, including Sun Microsystems' Forte, Borland's JBuilder, and Emacs,
making AspectJ a useful AOP implementation for Java developers.
AspectJ language overview
To support AOP, AspectJ adds to the Java language concepts:
- Joinpoints: Points in a program's execution. For example, joinpoints could define calls to specific methods in a class
- Pointcuts: Program constructs to designate joinpoints and collect specific context at those points
- Advices: Code that runs upon meeting certain conditions. For example, an advice could log a message before executing a joinpoint
Pointcut and advice together specify weaving rules. Aspect, a class-like concept, puts pointcuts and advices together to form
a crosscutting unit. The pointcuts specify execution points and the weaving rule's context, whereas the advices specify actions,
operations, or decisions performed at those points. You can also look at joinpoints as a set of events in response to which
you execute certain advices.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- Visit the AspectJ Website. Consider joining the mailing list, as it's a good AspectJ information source
http://aspectj.org
- Download the AspectJ compiler and tools
http://aspectj.org/servlets/AJSite?channel=download&subChannel=compilerAndTools
- Download the AspectJ Programming Guide for a more detailed understanding of AspectJ
http://aspectj.org/doc/dist/progguide/index.html
- "Improve Modularity with Aspect-Oriented Programming," Nicholas Lesiecki (IBM developerWorks, January 2002)
http://www-106.ibm.com/developerworks/java/library/j-aspectj
- This article's example aspect detects potential problems with threads and a Swing UI. To understand the situation better,
read "Threads and Swing" from the Java Tutorial (Sun Microsystems, Inc.)
http://java.sun.com/docs/books/tutorial/uiswing/overview/threads.html
- You'll find links to many tools, papers, and other resources at the "aspect-oriented software development" Website
http://aosd.net
- IBM offers HyperJ, a free implementation of multidimensional separation of concerns for Java
http://www.research.ibm.com/hyperspace/HyperJ/HyperJ.htm
- Adaptive programming is a special AOP case. Read about DemeterJ, a free implementation of adaptive programming for Java
http://www.ccs.neu.edu/research/demeter
- Ramnivas Laddad's "XML APIs for Databases" (JavaWorld, January 2000) explains how to blend the power of XML and databases using custom SAX and DOM APIs
http://www.javaworld.com/javaworld/jw-01-2000/jw-01-dbxml.html
- The Object-Oriented Design and Programming section of JavaWorld's Topical Index features numerous articles addressing design
http://www.javaworld.com/channel_content/jw-oop-index.shtml
- For tips and tutorials covering design patterns, development tools, performance tuning, security, testing, and more, sign
up for our free weekly Applied Java email newsletter
http://www.javaworld.com/subscribe
- Speak out in our Programming Theory & Practice discussion
http://forums.idg.net/webx?50@@.ee6b806
- You'll find a wealth of IT-related articles from our sister publications at IDG.net
Nice ArticleBy Anonymous on February 10, 2009, 5:50 amSimply gr8, nicely covered in implentation point of view
Reply | Read entire comment
View all comments