SlideShare a Scribd company logo
18/10/2013


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.










Centralize concerns implementation
More reusable code
Cleaner code
Write less code
Easy to understand
More maintainable
Less boilerplate code
More interesting work
Caching

Profiling


Aspects are often described in terms of
advice, pointcuts, and join points.







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.
Advice

Method

Joinpoints

Logger

Method

Transaction
Manager

Concern

Method

Concern


Before Advice



After Advice



After returning Advice



Around Advice



Throws Advice

Method

Method

Method
Method

Exception




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.


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));


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.


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.


saveCustomer(cus)
CustomerService

Customer
DAO

Proxy

Logger(Aspect)
Aspect Oriented Programming
Aspect Oriented Programming


AspectJ



AspectWrekz



JBossAOP



Spring AOP
Aspect Oriented Programming
1.

Spring AOP (using XML)

2.

Spring AoP ( using AspectJ Annotations)

3.

AspectJ ( using aspect class)
– An Logger Example
Aspect Oriented Programming
Aspect Oriented Programming






Cuts across multiple abstractions
Difficult to decompose
High-coupling
Boilerplate code
Code tangling and scattering
◦
◦
◦
◦

Poor traceability
Lower productivity
Less code reuse
Harder refactoring
AspectJ

Advice
advice body

pointcut

join point

Java Program










call(method signature)
handler(exception name)
cflow(join point designator)
this(type name)
target(type name)
within(class name)
execution(method signature)
get(signature), set(signature)
initialization(signature),
staticinitialization(type name)








call(* foo())
call(public bar.*(..))
call(void foo(..))
call(* *(..))
call(*.new(int, int))
handler(File*Exception)
Aspect Oriented Programming
Aspect Oriented Programming

More Related Content

PPTX
Integrated service digital network
PPTX
Azure Sentinel.pptx
PDF
PMI-ACP Domain VI: Problem Detection and Resolution v1.0
PPTX
Adaptive software development
PPTX
Ipv6 the next generation protocol
PPTX
Newton’s Forward & backward interpolation
PPTX
ISO 9000
PPT
Quality Management in Software Engineering SE24
Integrated service digital network
Azure Sentinel.pptx
PMI-ACP Domain VI: Problem Detection and Resolution v1.0
Adaptive software development
Ipv6 the next generation protocol
Newton’s Forward & backward interpolation
ISO 9000
Quality Management in Software Engineering SE24

What's hot (20)

PPTX
Aspect Oriented Programming
PPT
Aspect Oriented Programming
PPTX
Java servlets
PPTX
Introduction to Aspect Oriented Programming
PPTX
java Servlet technology
PPT
UML Diagrams
PPTX
Java Spring Framework
PPTX
Introduction to Spring Framework
PPT
Analysis modeling
PPT
Design Patterns
PDF
Java Design Patterns Tutorial | Edureka
PPT
Spring AOP
PPT
Oops ppt
PPTX
Servlets
PPTX
Angularjs PPT
PPT
Object and class relationships
PPTX
object oriented methodologies
PPTX
Assemblies
PPTX
Component based software engineering
Aspect Oriented Programming
Aspect Oriented Programming
Java servlets
Introduction to Aspect Oriented Programming
java Servlet technology
UML Diagrams
Java Spring Framework
Introduction to Spring Framework
Analysis modeling
Design Patterns
Java Design Patterns Tutorial | Edureka
Spring AOP
Oops ppt
Servlets
Angularjs PPT
Object and class relationships
object oriented methodologies
Assemblies
Component based software engineering
Ad

Viewers also liked (6)

PPTX
Introduction To Aspect Oriented Programming
PPTX
Aspect Oriented Programming
PPTX
Introduction to Aspect Oriented Programming (DDD South West 4.0)
PDF
PDF
Aspect-Oriented Programming (AOP) in .NET
PPTX
Introduction to Aspect Oriented Programming
Introduction To Aspect Oriented Programming
Aspect Oriented Programming
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Aspect-Oriented Programming (AOP) in .NET
Introduction to Aspect Oriented Programming
Ad

Similar to Aspect Oriented Programming (20)

PPTX
PDF
AOP (Aspect-Oriented Programming) spring boot
PPTX
spring aop
PDF
Spring Framework
PPTX
Spring AOP in Nutshell
PPT
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
PPSX
Spring AOP
PDF
Spring aop
PPTX
Introduction to Spring
PDF
Elements of DDD with ASP.NET MVC & Entity Framework Code First
PPSX
Spring - Part 3 - AOP
PPT
Aspect Oriented Software Development
PPTX
Session 45 - Spring - Part 3 - AOP
PPTX
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
PDF
Top 7 Angular Best Practices to Organize Your Angular App
PPTX
Performance analysis of synchronisation problem
PPTX
Spring aop
PDF
Angular2 with type script
PDF
Nt1310 Unit 3 Language Analysis
PDF
Objective-C
AOP (Aspect-Oriented Programming) spring boot
spring aop
Spring Framework
Spring AOP in Nutshell
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
Spring AOP
Spring aop
Introduction to Spring
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Spring - Part 3 - AOP
Aspect Oriented Software Development
Session 45 - Spring - Part 3 - AOP
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Top 7 Angular Best Practices to Organize Your Angular App
Performance analysis of synchronisation problem
Spring aop
Angular2 with type script
Nt1310 Unit 3 Language Analysis
Objective-C

Recently uploaded (20)

PDF
TR - Agricultural Crops Production NC III.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Basic Mud Logging Guide for educational purpose
PDF
RMMM.pdf make it easy to upload and study
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Pharma ospi slides which help in ospi learning
PDF
Complications of Minimal Access Surgery at WLH
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Lesson notes of climatology university.
PDF
VCE English Exam - Section C Student Revision Booklet
TR - Agricultural Crops Production NC III.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Anesthesia in Laparoscopic Surgery in India
Final Presentation General Medicine 03-08-2024.pptx
Computing-Curriculum for Schools in Ghana
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Basic Mud Logging Guide for educational purpose
RMMM.pdf make it easy to upload and study
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Sports Quiz easy sports quiz sports quiz
Pharma ospi slides which help in ospi learning
Complications of Minimal Access Surgery at WLH
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Microbial diseases, their pathogenesis and prophylaxis
PPH.pptx obstetrics and gynecology in nursing
Lesson notes of climatology university.
VCE English Exam - Section C Student Revision Booklet

Aspect Oriented Programming

Editor's Notes

  • #4: Intercept method callsInject new behaviour
  • #5: 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
  • #7: 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.
  • #9: 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}
  • #13: 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.
  • #14: http://www.intertech.com/Blog/secrets-of-the-spring-aop-proxy/