Overview of AOP

What is AOP?

It is beyond the scope of this guide to explain in detail aspect-oriented programming, but a rudimentary understanding is in order if you are to use the ACTF Java Validation components successfully. In object-oriented programming (OOP), a class (or set of classes) embodies a set of related concerns of an application. For instance, the Customer, Account, and Transaction classes in a banking application would attempt to capture deposits, withdrawls, and transfers by customers at a bank. These concerns are similar in function and purpose so that they are grouped together in tightly-woven classes.

Other concerns such as logging, debugging, performance, and, in our case, validation, are "cross-cutting" concerns. Such concerns cannot be limited to a class or set of classes and, in fact, permeate or are woven throughout the entire application. These concerns are the realm of aspect-oriented programming (AOP) rather than object-oriented programming.

There are two components of an aspect:

  1. The set of execution points in the application in which we are interested.
  2. The behavior that is to be performed before, after, or during the execution points in the application.

We use pointcut expressions to describe the set of execution points in an application that we want to aspect and bindings to associate advice with the set of execution points. Execution points may include method or constructor invocations, field accesses (the reading or writing of any field), the throwing of an exception, or some combination of all of these. Advice is anything that can be written in Java code and is executed whenever the associated joinpoint is encountered in execution.

Note: Execution points defined by aspects and those defined by ACTF are not the same, although they do have similar uses in each application. An execution point in an aspect defines where during the execution the advice is to be invoked whereas an execution point in ACTF defines where a validation process is initiated.

AOP Engines

AOP engines handle the details of weaving advice into Java classes so that it is executed whenever the pointcuts associated with that advice are encountered. The ACTF Java Validation componentry supports one AOP engine, AspectJ. The AspectJ engine is included with ACTF and is the default AOP engine for AOP-based validations. It is also the engine for which ACTF is configured when installed. The remainder of this section discusses the configuration and use of this engine.