WELCOME Abdennour : Software engineer

Mar 22, 2012

AOP Spring Step By Step(PART2) برمجة الهيئات

 برمجة آسبكت  
AOP terminology 
We have seen some Problems with OOP ,
However ,Aspect-oriented programming(Aop)  is an enhancement of OOP.In fact, AOP allows:

  • The modularization of crosscutting concerns by its constructs.
  • The uncoupling of the modules

    =>    Using aspects, the removal of dependence of a crosscutting concern from the modules that use it.

 OOP vs OAP (Invocation Methods):

the crosscutting functionalities are extracted from the object-oriented implementations and applied as advices the crosscutting concerns are
included into the classes'

What's advice?
-it's a job of an aspect .

=>it defines both the what and the when of an aspect
=>it addresses the question of when to perform the job.

Spring aspects can work with five kinds of advice :
    1)Before(advice functionality takes place before invocate 
    2)After(advice functionality takes place After method complete regardless of the outcome.)
     3)After-Returning : advice functionality takes place after the advised method successfully completes.
     4)After-throwing:advice functionality takes place after the advised method throws an exception.
     5)Around:Adivce wraps(emballer) the adviced method(Before&After)

What's a JointPoints?
-it's  opportunities for advice to be applied.
*This point could be :
1)a method being called,
2)an exception being thrown,
3)a field being modified.
==> There are 3 places where aspect’s code can be inserted into the normal flow of th application to add new behavior.
What's a PointCut?
If advice defines the what and when of aspects, then pointcuts define the where.
-pointcut definition matches one or more join points at which advice should be woven.

-to specify these pointcuts ,using :
1)explicit class and method names
2)regular expressions that define matching class and method name patterns

An aspect is the merger of advice and pointcuts.
=>what it does and where and when it does it.

INTRODUCTIONS : allows you to add new methods or attributes to existing classes.

the process of applying aspects to a target object to create a new proxied

-The weaving take place at several points in the target object’s lifetime:
1)Compile time:Aspects are woven in when the target class is compiled.
=>The weaver is AspectJ’s weaving compiler .
2)Classload time:Aspects are woven in when the target class is loaded into the JVM.
=> AspectJ 5’s load-time weaving (LTW) supports this Weaving.
3)Runtime:Aspects are woven in sometime during the execution of the application.

  • How Spring AOP aspects are woven ?
an AOP container will dynamically generate a proxy object that will delegate to the target object while (durant) weaving in the aspects.

In Brief :
1)ADVICE:(  Java Code)contains the cross-cutting behavior that needs to be applied to an application’s objects.
2)JointPoints: are all the points within the execution flow of the application that are candidates to have advice applied.
3)pointcut :(XML Code)defines where (at what join points) that advice is applied.
==>Pointcuts define which join points get advised.

Most Dominants AOP FrameWorks :
   1. AspectJ (http://eclipse.org/aspectj)

   2. JBoss AOP (http://www.jboss.org/jbossaop)

   3. Spring AOP (http://www.springframework.org)

        >  Spring Classic AOP  => Working directly with ProxyFactoryBean.
        > AspectJ now supports annotation-based aspects.

1 comment: