Java Reference
In-Depth Information
5.3.1. What is AOP?
It's very likely you've come across the term aspect-oriented programming (AOP). The es-
sential idea behind AOP is that for most applications, common code that doesn't neces-
sarily solve the core business problem and is repeated across components is considered an
infrastructure concern and shouldn't be part of the core business logic. The common term
used to describe these cases is crosscutting concerns —concerns that cut across application
Crosscutting concerns
The most commonly cited example of this is logging, especially at the basic debugging
level. To use the ActionBazaar example, let's assume that you log the entry into every
method in the system. This would mean adding logging statements at the beginning of
every single method in the system to log the action of “entering method XX”! This logic
would be copied and pasted everywhere and have little to do with actual business logic.
Some other common examples of crosscutting logic are auditing, profiling, and statistics.
An AOP system allows the separation of crosscutting concerns into their own modules.
Logging, auditing, profiling, and statistics would all become their own modules. These
modules are then applied across the relevant cross-sections of application code, such as
the beginning and end of every method call. EJB 3 supports crosscutting functionality by
providing the ability to intercept business methods and lifecycle callbacks. We'll now jump
into world of EJB 3 interceptors. You'll learn what interceptors are and how to build both
business method and lifecycle callback interceptors.
5.3.2. Interceptor basics
To understand the basics of EJB interceptors, let's first briefly look at the basic concepts
defined by AOP.
First is the concern (or crosscutting concern). The concern, so named, defines what you're
concerned about. For example, I'm concerned about adding logging to all of my business
methods, or I'm concerned about making sure all numbers are consistently rounded to a
certain number of decimal points.
Search WWH ::

Custom Search