Is a programming paradigm Extends OOP Enables modularization of cross cutting concerns
Dependency Injection Target code depends on the behavior to be applied AOP Applying a common behavior to large number of elements of code. Raise your hand if you want a Pizza ! Monday 9 AM
Interception Introduction Inspection Modularization / Encapsulation Open classes – extend classes Reflection – query meta data YES
Meta Programming Program as Data Read, generate, modify, analyze or transform other programs (itself) Code modified at run time Can we use it to do AOP? Is it effective? AOP Uses meta programming as a Vehicle. Uses the meta programming concepts Frameworks :- Aquarium AspectR
Aspect Advice Pointcut Join Point Weaver
Pointcut execution – applied to methods Within – applied to class level Args – applied based on the parameters to methods Advice
Any public method execution(public * * (..)) any method with a name beginning with “get“ execution(* get*(..)) Any method with a name beginging with “set” and has more than one parameter execution(* set*(*)) Any method defined in the appropriate package execution(* edu.diging.controller.*.*(..))
@Aspect public class EmployeeAspectPointcut public void transactionAdvice(JointPoint jointPoint){ System.out.println("Executing firstAdvice on ="+joinPoint.toString()); System.out.println("Agruments Passed=" + Arrays.toString(joinPoint.getArgs())); public void customAdvice(){ System.out.println("Executing secondAdvice on getName()"); String getName(*))") public void getNamePointcut(){} }
A standardized AOP framework has never really taken off in Ruby because the language itself already supports most of the desirable functionality of AOP. David Heinemeier Hansson of Rails fame
Aquarium can run on Jruby Ruby Aspects can advise Java Java aspects can advise Ruby
Promotes separation of concerns Code reuse and modularization Loose coupling
Thank you