September 01, 2001
The First Aspect-Oriented CompilerXerox PARC's AspectJ extension is to Java what C++ is to C.
It's not every day, or every year, that you come across something that makes you rethink your entire approach to programming. Mark my words, aspects are going to cause an epochal shift in programming right up there with the object shift of a decade ago. Just as objects did, aspects (and the de rigueur "aspect-oriented programming" and even "aspect orientation") facilitate an important and beneficial approach to system structure. The hype cycle has just begun; the backlash is just as inevitable, but there is no question that within a few years, aspects will be as much a part of the programming lexicon as objects are today. AspectJ is an extension to the Java language that provides Java with aspects in a manner analogous to the way C++ provides C with objects. The AspectJ compiler can produce either Java bytecodes or Java source code. AspectJ is being built by Xerox PARC by a team led by Gregor Kiczales, principal scientist and manager of Xerox PARC's software design area; it is freely available at www.aspectj.org and is partially supported by DARPA (Defense Advanced Research Projects Agency)so download it, 'cause you're paying for it anyway. So what are aspects? According to the Aspect-Oriented Programming Homepage,"Aspect-oriented programming (AOP) is a new programming methodology that enables the modularization of crosscutting concerns." The key word is crosscutting: Aspects allow you to attach behavior throughout your system regardless of function calls (the procedural way to associate two parts of a program) or inheritance (an object-oriented alternative way to associate system components). Like inheritance, to be interesting, an aspect has to involve at least three system components: a caller, a receiver, and another, less obvious, participant. In inheritance, a call (or access to a field) may be handled by an "ancestor" object. In aspect-oriented programming, a call or access can be intercepted by an aspect. The events of a running system where an aspect can attach are called join points, and the behavior of the aspect is called the aspect's advice.
The obvious places where aspects can benefit almost any program include debugging support, logging, security and context management, all of which concern most classes in a system and all of which happen to be of particular interest to Web Service developers. Another incredibly exciting feature of AspectJ is the use of aspects to facilitate roles in patterns. For instance, an aspect can be declared to "+ implements" a class, attaching both the abstract interface and the implementation to an existing class. This is such a powerful design and implementation capability that it's scaryyou could essentially build a class from multiple aspects, each of which reflects one component of the class's overall responsibilities. You could, but should you? Some will say that there's nothing that can be done with AspectJ that can't be done with Java. That's true, just as nothing can be done with C++ that can't be done with C. The issue with programming languages is rarely whether something is possibleit's whether that thing is facilitated. C facilitates manipulation of data at the level of bits and bytes, Perl facilitates string manipulation, Smalltalk facilitates object orientation, and AspectJ facilitates aspect-oriented programming. I'm convinced that aspects will be as significant as objects because the capabilities of aspect orientation align well with the needs of today's programmers, even as there's a restlessness about the solution (objects as the be-all and end-all of system structure) that we have at hand. You shouldn't underestimate the power of that restlessness, especially with a group of people as creative yet as reliant on tool support as programmers. Should you consider using AspectJ for your next project? This is a harder question to answer affirmatively. The problem isn't so much the tool; because AspectJ is translator-based, you won't lose access to underlying facilities. But many, if not most, people moving to object orientation had less-than-stellar experiences if the initial project was complex or under schedule pressure. The move toward developing Web-based services, on the other hand, was less traumatic for programmers, since what changed was not fundamental programming concepts so much as "just" the deployment platform. When you combine a new project with a new programming concept, the temptation to use the concept can be so strong that you end up using it everywhere and for everything, ignoring the strengths and techniques that you've built up over your career. It's one measure of the uniqueness of aspects that I think the first place you should use them (aside from exploring them in weekend projects) is in maintenance. If I were asked to add a new feature to an existing, complex system, I would definitely consider using aspectsif the customer was willing to withstand the various risks associated with AspectJ (chief of which is that either the AspectJ language or the programming community for it may atrophy). The crosscutting nature of aspects is perfectly suited to fitting new functionality into an existing system with minimal modifications (or even, conceivably, none). AspectJ is the best tool to help Java programmers investigate an exciting programming concept whose time on the main stage of software development has come. Do yourself a favordownload it today.
|
|
|||||||||||||||||||||||||||||||||||||
|
|
|
|