AOP Definitions
October 7th, 2006 Posted in UncategorizedAspect-Oriented Programming (AOP) complements OOP by providing another way of thinking about program structure. While OO decomposes applications into a hierarchy of objects, AOP decomposes programs into aspects or concerns. This enables modularization of concerns such as transaction management that would otherwise cut across multiple objects. (Such concerns are often termed crosscutting concerns.)
AOP Concepts
There are two distinct types of AOP:
- static: crosscutting logic is applied to your code at compile time, and you cannot change it without modifying the code and recompiling. Aspectj provides this type of implementation.
- dynamic: With dynamic AOP, like spring AOP, crosscutting logic is applied dynamically, at runtime.
These types of AOP are complementary and, when used together, they form a powerful combination that you can use in your applications.In defining the copcepts of AOP the definitions that I use will be SpringFramwork centric.
- Aspect: A modularization of a concern for which the implementation might otherwise cut across multiple objects. Transaction management is a good example of a crosscutting concern in J2EE applications. Aspects are implemented using Spring as Advisors or interceptors.
- Joinpoint: Point during the execution of a program, such as a method invocation or a particular exception being thrown. In Spring AOP, a joinpoint is always method invocation. Spring does not use the term joinpoint prominently; joinpoint information is accessible through methods on the MethodInvocation argument passed to interceptors, and is evaluated by implementations of the org.springframework.aop.Pointcut interface.
- Advice: Action taken by the AOP framework at a particular joinpoint. Different types of advice include “around,” “before” and “throws” advice. Advice types are discussed below. Many AOP frameworks, including Spring, model an advice as an interceptor, maintaining a chain of interceptors “around” the joinpoint.
- Pointcuts: Are predicates determining which joinpoints a piece of advice should apply to. It’s more intuitive — although not entirely accurate — to think of a pointcut as a set of jointponts. Pointcuts identify where advice should apply. Thye majic of AOP lies more in the specification of where action should be taken (pointcut) than what action to apply (advice).
Spring Advice Types
- Around Advice: Advice that surrounds a joinpoint such as a method invocation. This is the most powerful kind of advice. Around advices will perform custom behavior before and after the method invocation. They are responsible for choosing whether to proceed to the joinpoint or to shortcut executing by returning their own return value or throwing an exception.
- Before Advice: Advice that executes before a joinpoint, but which does not have the ability to prevent execution flow proceeding to the joinpoint (unless it throws an exception).
- After Returning Advice: is invoked when a method returns successfully, without throwing an exception. As with before advice, the return type is void; after returning advices are not intended to change the return value.
- Throws Advice: Advice to be executed if a method throws an exception. Spring provides strongly typed throws advice, so you can write code that catches the exception (and subclasses) you’re interested in, without needing to cast from Throwable or Exception.
3 Trackback(s)
You must be logged in to post a comment.