SlideShare une entreprise Scribd logo
1  sur  26
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)


AspectJ



AspectWrekz



JBossAOP



Spring AOP
1.

Spring AOP (using XML)

2.

Spring AoP ( using AspectJ Annotations)

3.

AspectJ ( using aspect class)
– An Logger Example






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

Contenu connexe

Tendances

11 ooad uml-14
11 ooad uml-1411 ooad uml-14
11 ooad uml-14
Niit Care
 

Tendances (20)

Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns ppt
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Modules in AngularJs
Modules in AngularJsModules in AngularJs
Modules in AngularJs
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 
UML
UMLUML
UML
 
11 ooad uml-14
11 ooad uml-1411 ooad uml-14
11 ooad uml-14
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
 
Software Architecture Patterns
Software Architecture PatternsSoftware Architecture Patterns
Software Architecture Patterns
 
Sessions and cookies
Sessions and cookiesSessions and cookies
Sessions and cookies
 
Presentation on uml
Presentation on umlPresentation on uml
Presentation on uml
 
Design Patterns Illustrated
Design Patterns IllustratedDesign Patterns Illustrated
Design Patterns Illustrated
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Grasp patterns and its types
Grasp patterns and its typesGrasp patterns and its types
Grasp patterns and its types
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Java Spring
Java SpringJava Spring
Java Spring
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 
Component and Deployment Diagram - Brief Overview
Component and Deployment Diagram - Brief OverviewComponent and Deployment Diagram - Brief Overview
Component and Deployment Diagram - Brief Overview
 

En vedette (6)

Introduction To Aspect Oriented Programming
Introduction To Aspect Oriented ProgrammingIntroduction To Aspect Oriented Programming
Introduction To Aspect Oriented Programming
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)
 
AOP
AOPAOP
AOP
 
Aspect-Oriented Programming (AOP) in .NET
Aspect-Oriented Programming (AOP) in .NETAspect-Oriented Programming (AOP) in .NET
Aspect-Oriented Programming (AOP) in .NET
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 

Similaire à Aspect Oriented Programming

Spring AOP
Spring AOPSpring AOP
Spring AOP
cteguh
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
Sujit Kumar
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software Development
Jignesh Patel
 
Nt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language Analysis
Nicole Gomez
 

Similaire à Aspect Oriented Programming (20)

Spring AOP
Spring AOPSpring AOP
Spring AOP
 
spring aop
spring aopspring aop
spring aop
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring AOP in Nutshell
Spring AOP in Nutshell Spring AOP in Nutshell
Spring AOP in Nutshell
 
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC TeamAOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Spring aop
Spring aopSpring aop
Spring aop
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software Development
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
Top 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppTop 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular App
 
Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problem
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Spring aop
Spring aopSpring aop
Spring aop
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type script
 
Nt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language Analysis
 
Objective-C
Objective-CObjective-C
Objective-C
 

Dernier

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Aspect Oriented Programming

Notes de l'éditeur

  1. Intercept method callsInject new behaviour
  2. 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
  3. 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.
  4. 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}
  5. 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.
  6. http://www.intertech.com/Blog/secrets-of-the-spring-aop-proxy/