2.
Aspect oriented programming (AOP) allows us to keep
implement different concerns in isolation
Cross-cutting concerns are conceptually separate from (but
often embedded directly within) the application’s business
logic. Separating these cross-cutting concerns from the
business logic is where aspect- oriented programming
(AOP) goes to work.
Whereas DI helps you decouple your application objects
from each other, AOP helps you decouple cross-cutting
concerns from the objects that they affect.
5.
Aspects are often described in terms of
advice, pointcuts, and join points.
6.
Advice defines what needs to be applied and
when.
Jointpoint is where the advice is applied.
Pointcut is the combination of different
joinpoints where the advice needs to be
applied.
Aspect is applying the Advice at the
pointcuts.
9.
your application may have thousands of
opportunities for advice to be applied. These
opportunities are known as join points.
These are the points where your aspect’s
code can be inserted into the normal flow of
your application to add new behavior.
10.
Pointcuts help nar- row down the join points
advised by an aspect. If advice defines the
what and when of aspects, then pointcuts
define the where
pointcut move():
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point));
11.
An aspect is the merger of advice and
pointcuts. Taken together, advice and pointcuts define everything there is to know about
an aspect—what it does and where and when
it does it.
12.
Weaving is the process of applying aspects to a target object to create a new
proxied object. The aspects are woven into the target object at the specified
join points. The weaving can take place at several points in the target object’s
lifetime:
◦ Compile time —Aspects are woven in when the target class is compiled.
◦ Classload time —Aspects are woven in when the target class is loaded into
the JVM.
◦ Runtime —Aspects are woven in sometime during the execution of the
applica- tion. Typically, an AOP container will dynamically generate a proxy
object that will delegate to the target object while weaving in the aspects.
Profiling is a form of dynamic program analysis that measures space (memory) or time complexity of a program, the usage of particular instructions, or frequency and duration of function calls. The most common use of profiling information is to aid program optimization.Pooling http://docs.oracle.com/javase/tutorial/jndi/ldap/pool.html
Join points are places in your code where an aspect can be inserted, for example, before and after a method call, when a method excepts, or when field or property is being accessed.An advice is a piece of code that can be injected at join points to add new behaviour.This is the boilerplate that you had taken out from your code so that you can encapsulate it into an aspect and then inject it in whilst keeping your code pretty.A point cut is a set of join points where an advice can be applied. It can be attribute drive, like the earlier example of ‘GetBookById’ method where we applied the two attributes to the method.Or it can be filter driven, like the second example where we applied the attributes to the class instead and targeted methods that met our criteria.When a point cut is matched, advice can be executed.An aspect contains point cuts and advice, it is to AOP what class is to OOP, whereas classes holds methods and properties, aspects holds point cuts and advice.Weaving is the process of taking the advice and injecting them into the point cuts in the core component and compose the final result.
Spring aspects can work with five kinds of advice: Before—The advice functionality takes place before the advised method is invoked. After—The advice functionality takes place after the advised method completes, regardless of the outcome. After-returning—The advice functionality takes place after the advised method successfully completes. After-throwing—The advice functionality takes place after the advised method throws an exception. Around—The advice wraps the advised method, providing some functionality before and after the advised method is invoked. Syntax-----------before(param) : pointcut(param) {body}after(param) : pointcut(param) {body}after(param) returning []: pointcut(param) {body}after(param) throwing []: pointcut(param) {body}type around(param) [throws typelist] : pointcut(param) {body}
Compile time—Aspects are woven in when the target class is compiled. This requires a special compiler. AspectJ’s weaving compiler weaves aspects this way. Classload time—Aspects are woven in when the target class is loaded into the JVM. This requires a special ClassLoader that enhances that target class’s byte- code before the class is introduced into the application. AspectJ 5’s load-time weaving (LTW) support weaves aspects in this way. Runtime—Aspects are woven in sometime during the execution of the applica- tion. Typically, an AOP container will dynamically generate a proxy object that will delegate to the target object while weaving in the aspects. This is how Spring AOP aspects are woven.