8 Aspect-Oriented Programming (Interceptors)

WHAT’S IN THIS CHAPTER?            

  • Introduction to aspect-oriented programming
  • Aspects in Java
  • Using servlet filters as aspects
  • Aspects in Java EE, interceptors
  • EJB interceptors versus CDI interceptors

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

The wrox.com code download for this chapter is found at www.wrox.com/go/projavaeedesignpatterns on the Download Code tab. The code is in the Chapter 8 download and individually named according to the names throughout the chapter.

Aspect-oriented programming (AOP) is not a new concept. Its place in Java and third-party frameworks was secured from the early days of enterprise development. Despite this, it was not one of the classical design patterns listed in the GOF1 book.

AOP introduced a new concept and paradigm to programming. The idea relies on basing the code execution order on aspects. Each aspect intercepts the program’s execution and adds its own behavior before continuing with the call.

Aspects act like magic, adding further logic and behavior to the code at run time. However, this also brings an ambiguous and hard-to-follow code execution order that can often result in almost undebuggable code. AOP has many followers and fans, besides many haters.

Luckily, Java EE has a nice and clean implementation that can be helpful if it’s used in the right way and context.

WHAT IS ASPECT-ORIENTED PROGRAMMING?

Aspect-oriented programming (AOP) aims to add behavior to existing code or applications ...

Get Professional Java EE Design Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.