foreword

This is a timely book, about a powerful and widely used technology that continues to grow in importance.

Since the first edition of AspectJ in Action, much has changed in AspectJ and the broader environment. This comprehensive update squarely addresses these changes.

Among the changes, three issues stand out: important new capabilities of AspectJ, increasing interest in dynamic languages in general and on the JVM, and the emergence of AspectJ as a key practical technology in mainstream enterprise Java.

AspectJ has matured greatly since the first edition. It now has comprehensive support for Java annotations, along with support for other language improvements such as generics, variable-length argument lists, and covariant return types. Annotations fit hand in glove with AOP, providing an ideal way of adding information about program structure and semantics for use by aspects. For example, one concise aspect might add consistent additional behavior to all executions of a method with a given annotation; another might cause a set of classes to be annotated with a particular annotation to direct an enterprise framework to add behavior at runtime. These language enhancements not only simplify the authoring of many aspects—they also make AspectJ an ideal match for modern enterprise Java programming models, and truly a new language.

The last few years has seen a significant rise in interest in dynamic languages—many of which (such as Groovy) provide capabilities for metaprogramming. Although this is a welcome change, it has caused some confusion regarding the role of AOP. Metaprogramming can solve some of the problems solved by AOP, but it doesn’t directly offer the ability to exploit program structure in a complementary way to OOP that is core to AOP. This book will help you understand which approach is appropriate to your everyday problems and how you can use them together. Ramnivas Laddad neatly expresses the relationship between AOP and dynamic languages in Chapter 1: “…statically typed languages use AOP to gain metaprogramming support. In contrast, dynamic languages benefit from AOP as a disciplined application of metaprogramming.”

Another important change since the first edition of this book is the rise of modern frameworks, which constitutes a huge validation of AOP. Today, the Spring Framework has become the most popular component model for enterprise Java. Its core benefit—sophisticated provision of declarative services to simple POJOs containing business logic and unpolluted by infrastructure concerns—is built on AOP, and its popularity and proven usefulness demonstrate the benefits of the modularization AOP is designed to achieve. (Indeed, all modern enterprise Java technologies follow Spring’s approach of providing enterprise services with minimal infrastructure API calls in user code.) Furthermore, Spring 2.0 made the important architectural decision to adopt the AspectJ pointcut expression language—the heart of AspectJ—and a subset of the AspectJ annotation programming model as its preferred AOP programming model—another validation, which exposes more developers to the benefits of AspectJ.

As a result, AspectJ works hand in hand with Spring and is particularly relevant to solving enterprise Java problems. Ramnivas has embraced this synergy in this book: he explains clearly how you can benefit from AspectJ concepts if you’re already using Spring, and how AspectJ the language is a natural extension of the AOP concepts supported by Spring. Readers who aren’t using Spring will still benefit from the valuable case studies and examples the Spring AOP experience provides.

This practical bent is important and to be commended. Programming languages are only as valuable as their practical usage potential, as history repeatedly shows. Another key to practical usage potential is tool support. In the case of AspectJ, there has recently been a huge step forward in this regard. Improvements to the Eclipse AspectJ plugin (AJDT) have resulted in dramatic performance and stability improvements, making AspectJ easier for less experienced developers to use. Meanwhile, the new Spring Roo project (http://www.springsource.org/roo) makes innovative use of AspectJ in greatly simplifying the authoring of enterprise Java applications. Not only is this a further validation of AspectJ, but it also promises to make the full power of AspectJ available in a large number of applications without developers needing to make an explicit choice to adopt AspectJ.

Together, these advances remove a key practical barrier to adopting AspectJ. The remaining barrier to adoption is the effort in learning AOP and AspectJ concepts—an effort well worth making. Learning AspectJ is like learning to type: it requires the investment of some time up front to be able to reap ongoing rewards in productivity.

This book will make that effort as easy and as pleasurable as possible. As you learn about AOP and AspectJ, I highly recommend Ramnivas Laddad as your guide.

A long-term advocate of AOP, Ramnivas is outstandingly knowledgeable about his subject. Even more important, he deeply understands how it fits into a broader context. Through many years of experience as an enterprise architect and consultant, he has gained a deep practical knowledge about real-world problems, seeing aspects as just one (albeit an important) weapon in the armory of the modern architect. This experience stands out in the relevance and value of the examples and in the fact that the book is well balanced. Ramnivas isn’t a mere cheerleader, and he provides excellent discussion of alternatives to AOP that will help you make the right architectural choices.

Finally, this book, like the previous edition, is a pleasure to read. Clear, concisely worded, and well organized, it will make your navigation of AspectJ and AOP concepts easy.

I wish you great success with AspectJ and the Java platform, and I hope you enjoy reading this book as much as I have.

Rod Johnson
Creator of the Spring Framework