"A concern is a particular goal, concept, or area of interest. In technology terms, a typical software system comprises several core and system-level concerns. For example, a credit card processing system's core concern would process payments, while its system-level concerns would handle logging, transaction integrity, authentication, security, performance, and so on. Many such concerns -- known as crosscutting concerns -- tend to affect multiple implementation modules. Using current programming methodologies, crosscutting concerns span over multiple modules, resulting in systems that are harder to design, understand, implement, and evolve."
"Recently released Spring 2.0 provides excellent, easy-to-use AOP capabilities. Spring AOP is now remarkably easy to use for the average Java developer with traditional object-oriented programming skills. This story shows how Spring 2.0 AOP can be effectively used to implement crosscutting concerns in a typical software project. We will consider the following crosscutting concerns for implementation:"
"Next, you implement a no loitering-views concern, as Figure 3 shows. Instead of adding listeners to a model directly, you can wrap it as a referent in a WeakReference object and add it. Since the added object must be of the correct listener type, use the Decorator pattern in a class extending WeakReference and implementing the required listener interface. The decorator implements the listener interface by delegating each method to the referent object."
"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."
"In a complex distributed computing environment like J2EE, it is very difficult to pinpoint the component that is causing a performance bottleneck. Applications can be profiled by including instrumentation code manually, but this could be cumbersome and time-consuming, and might impact the stability of the application itself. Aspect-Oriented Programming (AOP) technology can be elegantly and effectively applied for performance analysis, as illustrated by Davies et al."
"Aspect-Oriented Programming (AOP) complements OO programming by allowing the developer to dynamically modify the static OO model to create a system that can grow to meet new requirements. Just as objects in the real world can change their states during their lifecycles, an application can adopt new characteristics as it develops."
"In this article, I'll use aspect oriented programming (AOP) as a means of intercepting Java methods that I want to upgrade. The intercepted code can then be added to the operational system to provide the required interim feature(s). For the next major release (following the upgrade), the upgrade code can then be moved out of the interception area into the main code base. This use of interception reduces the risk of updating the main class."
"I used JBossCache as the main framework to demonstrate aspect oriented object caching implementation in the sample web application. JBossCache provides two flavors of object caching implementation, TreeCache and TreeCacheAop. TreeCache is basically a structured object tree with nodes. The data stored in the cache is accessed by specifying a fully qualified name (FQN) which is the concatenation of all node names from root node to the current node. FQN is same as the region name used in other caching frameworks such as Java Caching System (JCS) and OSCache. A cache region is defined as an organizational name space for holding a collection of cache objects with similar characteristics (such as business usage and time to live). TreeCache can be used as a stand-alone cache (local) or a replicated cache (in a multi-server cluster environment). Also, the cache replication can be done asynchronously or synchronously (synchronous means the client request is not returned until all cache changes are replicated in the cluster nodes). JBossCache uses the JGroups framework for the group communication purposes when replicating the modifications in one cache to other caches in the cluster."
"In this article, Alexandre Vasseur explains how to make use of the rich semantics of the new AspectWerkz 2.x AOP framework and its annotation driven approach to implement a subset of the EJB 3 specification with Java 5: annotation driven Container Managed Transaction (CMT)."
"The AOP panel at JavaOne was a big success. Maybe it was because of the provocative title ("AOP : The next big thing or giant leap backward"), which was concocted by the mischievous Graham. Maybe it was because James draws a lot of attendance. Or maybe, just maybe, it's that more and more people are getting extremely curious about AOP."
"In this article, Jonas Bon?introduces the new AspectWerkz 2.x architecture. AspectWerkz 2.x has been designed to be an extensible AOP container where any kind of aspects can coexist ranging from Spring aspects to AspectJ aspects. The article explains why this architecture is beneficial to the Java AOP communtity and explains the benefits and drawbacks of running AOP Alliance, Spring and AspectJ aspects within the AspectWerkz Extensible Aspect Container. It concludes with performance figures."
"In the previous article of this series, we examined the fundamentals of aspect-oriented refactoring (AO refactoring), the general schemes and considerations involved, and the process through a simple example. By now, you should have a clear idea about AO refactoring. In this second and concluding part of the series, I will present several AO refactoring techniques."
"Aspect-oriented programming (AOP), although specialized in nature, can facilitate a range of useful separations of concerns. One such area is internationalization (often called "I18N" because of the 18 characters between the first and last letter of the word). I18N is big business in a global software marketplace. In this article I'll use AOP to show how part of the I18N problem can be solved with the use of aspects in an additive, not-too-invasive manner."
"The AOP implementation in this article is simplified for clarity, but it shows you the essentials of proxy-based AOP frameworks. AOP decouples crosscutting concerns, such as the transaction management demonstrated in this article, from application core concerns. With aspect-oriented design and programming, you can significantly simplify your design and implementation. In some cases, however, third-party AOP frameworks cannot be used due to non-technical reasons, such as corporate policies and license issues. As shown in this article, you can implement your own AOP framework that is tailored to meet your needs. JDK dynamic-proxy-based implementation is simpler, since it uses standard Java. That means there are no third-party libraries or build-time bytecode instrumentation. Alternatively, you can choose CGLIB to proxy legacy classes and have better performance, but you need to introduce multiple third-party libraries into your system. At that moment, you should ask yourself if you need to pick an available AOP framework, which is often more complete and sophisticated than your roll-your-own AOP implementation."
"We present three excerpts from AspectJ Cookbook, by Russell Miles, copyright 2004. All rights reserved. These sections are posted with permission from O'Reilly Media."
"This can be solved by making all of the JavaBeans implement an interface and using AspectJ to introduce methods to the interface. In this case, the interface name is hard-coded instead of the bean names. The following code snippet will show what we mean by this."
"This book excerpt is from Chapter 3 of AspectJ in Action: Practical Aspect-Oriented Programming by Ramnivas Laddad, ISBN 1-930110-93-6, copyright 2003. All rights reserved. This chapter, titled "AspectJ: syntax basics," is posted with permission from Manning Publications Co."
"Take the case of logging, for example. Logging code is scattered horizontally across multiple object hierarchies most of the time, and it has nothing to do with the functionalities the object hierarchies represent. In other words, OOP best depicts the top-down (vertical) object relationship but it falls short in handling left-to-right (horizontal) object relationship. Aspect-oriented programming (AOP) facilitates the latter by referring horizontal object relationships as crosscutting concerns and separating them from core functionalities."
"Trends within the Java community are modeling such concerns as aspects—important to the application but orthogonal to the main task at hand. Rather than coding this logic painstakingly throughout your application, wouldn't it be nice if you could just express this behavior in one place and have it apply to every class? With dynamic proxies, you can easily do so—and once you understand proxies, you've made a small conceptual leap towards the bigger picture—aspect-oriented programming (AOP)."
"AspectJ, a general-purpose, aspect-oriented extension to the Java language, is a collection of tools for AOP. Originally developed by professionals from Xerox's Palo Alto Research Center to grow the technology and community in 2002, it has since moved to the Eclipse Project. AspectJ contains expansions and tools that enable Java developers to better manage the problems in large program systems and to reap the benefits of modularity. AspectJ provides clean modularization of crosscutting concerns, such as:"
"A major focus of AspectJ 5 (now in its second milestone build) is on providing support for the new Java language features introduced in Java 5, including annotations and generics. AspectJ 5 also contains new features not tied to Java 5, such as an annotation-based development style, improved load-time weaving, and a new aspect instantiation model."
"My fascination with design patterns and AspectJ began with the Aspect-Oriented Design Pattern Implementation project (see Resources) sponsored by the University of British Columbia. As I mentioned in the first part of this article Jan Hanneman and Gregor Kiczales investigated the 23 GoF patterns and created reference implementations of each in both the Java language and in AspectJ. The results are fascinating to study, with 17 of the original patterns improving when implemented with AOP. Even more exciting is the Pattern Library. The project authors were able to extract reusable abstract aspects from 13 of the patterns and have made them freely available under the Mozilla Public License. The ObserverProtocol aspect shown in this article was taken from that project. See the Resources section to download the patterns."
"In Part 1 of this two-part AOP tools comparison, I showed you how the four leading AOP tools (AspectJ, AspectWerkz, JBoss AOP, and Spring AOP) implement the core AOP mechanisms. While the tools have converged on the idea of a join point model, pointcuts, advice, and inter-type declarations, there are significant trade-offs inherent in each tool's handling of AOP syntax. As I showed in Part 1, syntactic decisions not only affect what it feels like to program with aspects -- verbose syntax vs. more direct, pointcuts as code vs. annotations, stored in the same source file as advice vs. localized with the aspect configuration in XML -- but also make a difference when it comes to semantics. Now I'll continue to explore the implications of the different approaches, but this time focus on how the above decisions affect the tool's integration into the overall development process and environment."
"Like any new and exciting technology, AOP has generated its fair share of buzz, and also its fair share of myths and misunderstandings. After following AOP coverage on the Web and listening to the questions asked at conferences, I started to see some common themes (or myths) that deserve to be cleared up."
"My first attempt at modularizing a crosscutting concern employs a system-specific aspect that contains pointcut definitions as well as advice to that pointcut. This is a very simple scheme and very often the first design you'll encounter in learning about AOP. Figure 1 shows the schematics of a design that employs one aspect:"
"The new Crosscutting Comparison functionality -- added just in time for the AJDT 1.2.1 and 1.3 releases -- was developed precisely to assist you in handling these types of changes to your code. Crosscutting Comparisons allows you to take a snapshot of the crosscutting relationships in your project and then compare the snapshot with relationships present in a later version of the project. To create a snapshot, right-click on a project and select AspectJ Tools > Save Crosscutting Map. You will then be prompted for a filename to save the relationship map into. These files have the .ajmap extension, and are stored directly in your project. For example, when you release a particular version of your project, you might save the crosscutting relationships for that release, in order to use them as a point of reference when developing the next release."
"There's no magic potion in those two jars: merely advice in a library aspect, deployed using load-time weaving. The library aspect RethrowVMError runs advice before any overeager error handlers can get to it, preventing them from hiding VMErrors. AspectJ 5 has new language features that make it easier to write library aspects and new deployment options that make it easier to use concrete aspects. Together, these can bring AOP to a broad new class of less-experienced users (using less tolerant build or deployment processes) -- but only if the library aspects are well tailored. In this article, I'll enlist you, dear reader, as an expert in writing library aspects, or at least teach you enough to ask the right questions and deploy simple library aspect solutions based on the answers."
"I previously claimed that many patterns are crosscutting, but of course I wasn't the first one to think of this. A recent research paper analyzed the GoF patterns and found that 17 out of the 23 patterns exhibited some degree of crosscutting. (The paper is Jan Hannemann and Gregor Kiczales's "Design Pattern Implementation in Java AspectJ," see the Resources section for more details.) If AOP promises to help with crosscutting, what kind of benefits can you expect to see from using it on design patterns? I'll start by answering that question in general terms, and then set up a framework through which I'll consider each design pattern."
"You should download the current versions of AspectJ, JMX, and JMX Remote, as well as the source packet for this article (see Resources for the technologies and Download for the code) before continuing. If you are using a Java 5 VM, then it has JMX integrated into it. Note that the source packet includes the complete, final code for the 1.0 alpha release of the open source Glassbox Inspector performance monitoring infrastructure."
"In this second half of my foray into performance monitoring with AspectJ, I extend the Glassbox Inspector to provide more meaningful information about application performance by adding monitors that track the interaction of controllers for the Struts and Spring Web application frameworks, as well as serving and requesting Web services operations. I also extend the system to support multiple applications and add an error-handling layer and the ability to easily enable and disable monitoring at run time. I conclude the article by showing you how to deploy the Glassbox Inspector using load-time weaving and how to measure the resulting overhead."
"Aspect-oriented programming (AOP) grew out of a recognition that typical programs often exhibit behavior that does not fit naturally into a single program module, or even several closely related program modules. Aspect pioneers termed this type of behavior crosscutting because it cut across the typical divisions of responsibility in a given programming model. In object-oriented programming, for instance, the natural unit of modularity is the class, and a crosscutting concern is a concern that spans multiple classes. Typical crosscutting concerns include logging, context-sensitive error handling, performance optimization, and design patterns."
"Note that this is a two-part article, with both parts published simultaneously for your convenience. Part 1 focuses on how each of the four leading tools handles the AOP language mechanisms. Topics include differences and similarities among the tools' aspect syntax and pointcut expressiveness, and the range of mechanisms for declaring aspects. Part 2 continues with a closer look at how the leading AOP implementations integrate with existing development environments, tools, and libraries. Topics include aspect weavers, IDE plug-ins, scalability, and upcoming directions for AOP tools, including a focus on the recent merging of the AspectJ and AspectWerkz projects."
"Revisiting "JUnit: A Cook's Tour" was a good way to develop a better understanding of the ways AspectJ can minimize and control interaction at a join point, which is key to using pointcuts effectively in your design. Pattern density, which can make mature object-oriented frameworks hard to change, is a natural result of the way object-oriented developers design systems. The solutions presented here, by using a pointcut instead of an object, avoiding interactions where possible, and minimizing them otherwise, avoid the inflexibility of JUnit and show how you can do the same in your own designs. By avoiding design trade-off's developers have grown to accept, these solutions show that AOP can be useful even when the code is already thought to be well-modularized. I hope you are encouraged to try AOP in more applications, at full speed."
"DBC is especially valuable when you're dealing with external components or libraries and need to ensure that the data your application passes to them and receives from them is correct. This article will show you an abstract infrastructure that employs aspect-oriented programming (AOP) to implement DBC and then a sample application that establishes a contract with an external component."
"As realists, we acknowledge that no one process, technique, language, or platform is good for all situations. We increase the number of tools in our repertoire so that when we need that special tool or technique, we are well-prepared to use it. The history of our industry is rife with examples of improvements in our approach to building software, from the introduction of high-level languages, structured programming, and the object-oriented approach, to the development of spiral and iterative methods, and so on. One of the latest entrants in this lineup is aspect-oriented programming (AOP), which represents one facet of aspect-oriented software development (AOSD). In this month's column, I'll provide an overview of AOP and offer some observations on its promise, what we need to do to realize that promise, and some issues and obstacles along the way. We'll learn a little bit about AOSD, too."
"Java-based AOP employs a flexible and rich expression language with which you can slice and dice complex applications in a seemingly infinite number of ways. The Java-based AOP syntax is similar enough to the Java language that you should have little trouble grasping it. Once learned, AOP is a programming technique with many applications. In addition to comprehending legacy system internals, you can also use AOP to unobtrusively refactor and enhance such systems. Although you'll work entirely with AspectJ in this article, most of the techniques discussed are portable to other popular Java-based AOP implementations such as AspectWerkz and JBossAOP (see Resources)."
"Aspect orientation is a powerful principle to draw upon during the fast-paced cycle of transforming business requirements into software features. By shifting the primary design focus away from the traditional hierarchical nature of object-oriented programming (OOP), AOP and design principles allow software architects to contemplate design in a horizontal, yet complementary, manner to object orientation."
"By now, you've surely heard about aspect-oriented programming. You know that aspects are handy for logging and instrumentation, and you've heard that they can be applied to more complex problems as well. It may be that you've already downloaded and written some simple aspects yourself or tried a product such as the Spring Framework that uses AOP to simplify development. But where do you go from here? What else can aspects do for you?"
"While defensive programming effectively guarantees the condition of one method's input, it becomes repetitive if it is pervasive across a series of methods. Those familiar with aspect oriented programming, or AOP, will recognize this as a crosscutting concern, meaning that defensive programming techniques span horizontally across a code base. Many different objects employ these semantics, yet they have nothing to do with the object itself from a purely object-oriented view."
"While metadata is extremely useful when used in conjunction with AOP, there is a danger of overusing it. Overusing annotations under-utilizes the information inherently contained in the program element's signature and dynamic context. Adding metadata to your code also increases its complexity. First, program elements must carry metadata annotations. Second, incorrectly using metadata with AOP can lead to macros on steroids, which are very useful at first sight and save a lot of duplicated code, but make programs incomprehensible over time. It is, therefore, important to go beyond understanding the mechanics involved in combining AOP and metadata: It is also important to grasp the concepts and best practices entailed in using the two technologies together. In this section, I'll provide a series of guidelines for correctly combining metadata with AOP."
"In this article, I show you how to combine the dependency injection of the Spring framework effectively with aspects written using AspectJ 5. I assume you have a basic knowledge of AOP (although if you don't, you'll find some good starting points in the Resources section), so I'll begin my discussion by analyzing the key roles and responsibilities involved in a dependency injection-based solution. From there, I'll show you how to configure singleton aspects via dependency injection. Because configuring non-singleton aspects shares much in common with configuring domain objects, I'll then look at a simple solution that applies to them both. I conclude the article by showing you how to use aspects for several advanced dependency injection scenarios, including interface-based injection and repeated injection."
"In this final article in the AOP@Work series, I introduce you to Contract4J, an AspectJ-based tool that supports Design by Contract. I show you how to use Contract4J to implicitly specify component behavior, document proper component usage for clients, and programmatically test for compliance. At the end of the article, I discuss how Contract4J fits into emerging trends in aspect-oriented design."
"Apart from AspectJ, there are other implementations also available. Some of them are Spring, Jboss, and AspectWerks. It's up to you to choose the implementation that is right for you. AOP is easier to understand and implement. It achieves code reuse and modularization at much greater levels. It removes the cross cutting concerns and makes application loosely coupled and maintenance easy."
"To truly appreciate the advantages offered by AspectJ, let's consider implementing logging without AspectJ. Since logging is such a common requirement, APIs and libraries are available that let us perform logging consistently. Notable examples are the standard Java logging API and log4j from Apache. These toolkits provide an efficient and abstract access to the underlying logging mechanics. They enable us to easily switch between console, socket stream, native event logging, and so forth. In addition, they allow sophisticated formatting of log messages, including the XML format. These toolkits further allow the hierarchy of logger objects and offer an easy control over the information logged."
"Aspect Oriented Programming (AOP) is a promising new technology for separating crosscutting concerns that are usually hard to do in object-oriented programming. This article aims to be an introductory point to the basic concepts associated with this new paradigm."
"This week, our favorite resource from our Web Resources and Downloads directories is "Introducing AspectJ", a technical article available from IBM developerWorks, authored by Nicholas Lesiecki of eBlox Inc. (and author of Java Tools for Extreme Programming ). As you can infer, his paper "Improve Modularity with Aspect-Oriented Programming" is an introduction to the new programming methodology via the use of AspectJ, originally from the people at the Xerox PARC Software Design Area."
"Software development metrics are changing; it's no longer enough to know Java or C++, SQL, and some UML. Increasingly, developers have to be able to formulate solutions in completion or component form. Moving up the value chain is not a matter of choice for developers. What to do? One of the best investments a developer can make is gaining a solid knowledge of design patterns. Another beneficial area for study is architectural patterns. Software architecture patterns—just like design patterns—are a powerful tool for creating solid software solutions. One such pattern is used for creating software in layers; this allows for demarcation of special-purpose APIs such as Sun's Java Dynamic Management Kit (Java DMK). The layering pattern facilitates swapping out and replacing this API. You may have been using the layering pattern for years, but many programmers are unaware of the need for some associated architectural quality attributes: scalability, security, and modifiability."
"AOP isn’t a substitute for good design, but it can help in situations where a design team has produced a product that looks like Figure 1, but suddenly the marketing folks require the addition of a range of new crosscutting concerns. Rather than busting a gut hacking up the existing code structure, you can use aspects to implement the new required concerns. This is a production-time aspect, and I’ll discuss one of these shortly."
"An important aspect of AOP is that, used in isolation, it can facilitate a range of useful separations of concerns. One such area is internationalization (often called I18N because of the 18 characters between the first and last letter of the word). I18N is big business in a global software marketplace. In this article I'll use AOP to show how part of the I18N problem can be solved with the use of aspects in an additive, not-too-invasive manner. I call this low-touch programming (LTP)."
"Aspect-oriented programming (AOP), although far from a new topic, has recently become quite a hot one. Many folks in the coding industry are touting AOP as the successor to the object-oriented programming (OOP) model; however, as we'll see in this article, despite a similar acronym AOP addresses few if any of the same concerns as OOP. In short, AOP allows for code behavior to be divided into core components (aspects), which can be injected into arbitrary locations easily. Method calls can be intercepted, augmented, or redirected, as can field access and even inheritance?in many cases without code changes."