SlideShare una empresa de Scribd logo
1 de 21
Descargar para leer sin conexión
Aspect Oriented
Programming
Aspect-oriented programming with Spring framework
HISTORY
Chapter 1
Aspect Oriented Programming
Aspect Oriented Programming
 Gregor Kiczales
Gregor Kiczales is a professor
of computer science at the
University of British Columbia
in Canada.
His best-known work is on
aspect-oriented programming
and the AspectJ extension for
Java at Xerox PARC.
Wikipedia
Born: 1961
Alma mater: Massachusetts
Institute of Technology
Books: The Art of the
Metaobject Protocol
Aspect Oriented Programming
 US patented
INTRODUCTION
Chapter 2
Aspect Oriented Programming
as·pect
/ˈaspekt/
noun
1. a particular part or feature of something.
feature, facet, side, characteristic, particular, detail; angle, slant
a specific way in which something can be considered.
a particular appearance or quality.
appearance, look, air, cast, mien, demeanor, expression
2. the positioning of a building or thing in a specified direction
Aspect Oriented Programming
 Aspect Oriented Programming
In computing, aspect-oriented programming (AOP) is a
patented programming paradigm that aims to increase
modularity by allowing the separation of cross-cutting
concerns.
Wikipedia
Aspect-Oriented Programming (AOP) complements Object-Oriented
Programming (OOP) by providing another way of thinking about
program structure. The key unit of modularity in OOP is the class,
whereas in AOP the unit of modularity is the aspect. Aspects enable
the modularization of concerns such as transaction management that
cut across multiple types and objects. (Such concerns are often termed
crosscutting concerns in AOP literature.)
Spring framework reference
Aspect Oriented Programming
 AOP implemented languages
Java
AspectJ
JavaScript
Logtalk
Lua
make
Matlab
ML
Perl
PHP
Prolog
Python
Racket
Ruby
Squeak Smalltalk
UML 2.0
XM
.NET Framework languages
(C# / VB.NET)
ActionScript
Ada
AutoHotkey
C / C++
COBOL
The Cocoa Objective-C
frameworks
ColdFusion
Common Lisp
Delphi
Delphi Prism
e (IEEE 1647)
Emacs Lisp
Groovy
Haskell
TERMINOLOGY
Chapter 3
Aspect Oriented Programming
 AOP Terminologies
 Aspect: a modularization of a concern that cuts across multiple classes. Transaction management is a good example of a crosscutting concern
in enterprise Java applications. In Spring AOP, aspects are implemented using regular classes (the schema-based approach) or regular classes
annotated with the @Aspectannotation (the @AspectJ style).
 Join point: a point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a
join point alwaysrepresents a method execution.
 Advice: action taken by an aspect at a particular join point. Different types of advice include "around," "before" and "after" advice. (Advice
types are discussed below.) Many AOP frameworks, including Spring, model an advice as an interceptor, maintaining a chain of
interceptors around the join point.
 Pointcut: a predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the
pointcut (for example, the execution of a method with a certain name). The concept of join points as matched by pointcut expressions is
central to AOP, and Spring uses the AspectJ pointcut expression language by default.
 Introduction: declaring additional methods or fields on behalf of a type. Spring AOP allows you to introduce new interfaces (and a
corresponding implementation) to any advised object. For example, you could use an introduction to make a bean implement
an IsModified interface, to simplify caching. (An introduction is known as an inter-type declaration in the AspectJ community.)
 Target object: object being advised by one or more aspects. Also referred to as the advised object. Since Spring AOP is implemented using
runtime proxies, this object will always be a proxied object.
 AOP proxy: an object created by the AOP framework in order to implement the aspect contracts (advise method executions and so on). In the
Spring Framework, an AOP proxy will be a JDK dynamic proxy or a CGLIB proxy.
 Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the
AspectJ compiler, for example), load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime
Aspect Oriented Programming
 Types of advice
 Before advice: Advice that executes before a join point, but which does not have the ability to
prevent execution flow proceeding to the join point (unless it throws an exception).
 After returning advice: Advice to be executed after a join point completes normally: for example, if
a method returns without throwing an exception.
 After throwing advice: Advice to be executed if a method exits by throwing an exception.
 After (finally) advice: Advice to be executed regardless of the means by which a join point exits
(normal or exceptional return).
 Around advice: Advice that surrounds a join point such as a method invocation. This is the most
powerful kind of advice. Around advice can perform custom behavior before and after the
method invocation. It is also responsible for choosing whether to proceed to the join point or to
shortcut the advised method execution by returning its own return value or throwing an exception.
Aspect Oriented Programming
 AOP terminology
Advice injected code
Join Point a point of execution
Pointcut
point of injection
(set of Join Point)
Aspect Advice + Pointcut
Weaving process of injection
Aspect Oriented Programming
 AOP terminology
AOP PROXIES
Chapter 4
Aspect Oriented Programming
 Proxy
Structure
Aspect Oriented Programming
 Dynamic Proxy
Aspect Oriented Programming
public interface Foo {
Object bar(Object obj) throws BazException;
}
public class FooImpl implements Foo {
Object bar(Object obj) throws BazException {
// ...
}
}
public class DebugProxy implements java.lang.reflect.InvocationHandler {
private Object obj;
public static Object newInstance(Object obj) {
return java.lang.reflect.Proxy.newProxyInstance(
obj.getClass().getClassLoader(),
obj.getClass().getInterfaces(),
new DebugProxy(obj));
}
private DebugProxy(Object obj) {
this.obj = obj;
}
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable
{
Object result;
try {
System.out.println("before method " + m.getName());
result = m.invoke(obj, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (Exception e) {
throw new RuntimeException("unexpected invocation exception: " +
e.getMessage());
} finally {
System.out.println("after method " + m.getName());
}
return result;
}
} https://docs.oracle.com/javase/8/docs/technotes/guides/reflection/proxy.html
Aspect Oriented Programming
 Code Example
http://www.mkyong.com/spring/spring-aop-examples-advice/
Mobile API Cache
Aspect Oriented Programming
 AspectJ
AspectJ is an aspect-oriented programming (AOP) extension created at
PARC for the Java programming language.
It is available in Eclipse Foundation open-source project
Aspect Oriented Programming
 Reference
https://en.wikipedia.org/wiki/Aspect-oriented_programming
http://docs.spring.io/spring/docs/current/spring-framework-
reference/html/aop.html
https://www.opencredo.com/2015/07/14/dynamic-proxies-java-part-
2/
https://en.wikipedia.org/wiki/AspectJ
https://en.wikipedia.org/wiki/Spring_Framework#Aspect-
oriented_programming_framework
https://en.wikipedia.org/wiki/Aspect-oriented_software_development
http://www.eclipse.org/aspectj/
https://www.google.com/patents/US6467086
http://java2novice.com/spring/aop-and-aspectj-introduction/

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problem
 
Spring framework part 2
Spring framework  part 2Spring framework  part 2
Spring framework part 2
 
Introduction to AOP, AspectJ, and Explicit Join Points
Introduction to AOP, AspectJ, and Explicit Join PointsIntroduction to AOP, AspectJ, and Explicit Join Points
Introduction to AOP, AspectJ, and Explicit Join Points
 
What's new in c# 6.0
What's new in c# 6.0What's new in c# 6.0
What's new in c# 6.0
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design Patterns
 
Enriching EMF Models with Scala (quick overview)
Enriching EMF Models with Scala (quick overview)Enriching EMF Models with Scala (quick overview)
Enriching EMF Models with Scala (quick overview)
 
Why system verilog ?
Why system verilog ? Why system verilog ?
Why system verilog ?
 
C#/.NET Little Pitfalls
C#/.NET Little PitfallsC#/.NET Little Pitfalls
C#/.NET Little Pitfalls
 
Massively Scalable Applications - TechFerry
Massively Scalable Applications - TechFerryMassively Scalable Applications - TechFerry
Massively Scalable Applications - TechFerry
 
Styled Components & React.js
Styled Components & React.jsStyled Components & React.js
Styled Components & React.js
 
Quick Tour to Front-End Unit Testing Using Jasmine
Quick Tour to Front-End Unit Testing Using JasmineQuick Tour to Front-End Unit Testing Using Jasmine
Quick Tour to Front-End Unit Testing Using Jasmine
 
Sysprog 10
Sysprog 10Sysprog 10
Sysprog 10
 
Sysprog 10
Sysprog 10Sysprog 10
Sysprog 10
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
 
Front end unit testing using jasmine
Front end unit testing using jasmineFront end unit testing using jasmine
Front end unit testing using jasmine
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
spring aop
spring aopspring aop
spring aop
 
Styled components presentation
Styled components presentationStyled components presentation
Styled components presentation
 

Destacado

Aspect Oriented Programming and Design
Aspect Oriented Programming and DesignAspect Oriented Programming and Design
Aspect Oriented Programming and Design
Manikanda kumar
 
Aspect oriented programming_with_spring
Aspect oriented programming_with_springAspect oriented programming_with_spring
Aspect oriented programming_with_spring
Guo Albert
 
Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introduction
b0ris_1
 

Destacado (17)

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
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Aspect Oriented Programming and Design
Aspect Oriented Programming and DesignAspect Oriented Programming and Design
Aspect Oriented Programming and Design
 
Aspect oriented programming_with_spring
Aspect oriented programming_with_springAspect oriented programming_with_spring
Aspect oriented programming_with_spring
 
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 spring
Aop springAop spring
Aop spring
 
Aspect-Oriented Programming (AOP) in .NET
Aspect-Oriented Programming (AOP) in .NETAspect-Oriented Programming (AOP) in .NET
Aspect-Oriented Programming (AOP) in .NET
 
Spring AOP in Nutshell
Spring AOP in Nutshell Spring AOP in Nutshell
Spring AOP in Nutshell
 
Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introduction
 
AspectJ Android with Example
AspectJ Android with ExampleAspectJ Android with Example
AspectJ Android with Example
 
Aspect Oriented Programming (AOP) - A case study in Android
Aspect Oriented Programming (AOP) - A case study in AndroidAspect Oriented Programming (AOP) - A case study in Android
Aspect Oriented Programming (AOP) - A case study in Android
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 

Similar a AOP

Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
Sujit Kumar
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
Ganesh Samarthyam
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, android
i i
 
Object Oriented Programming All Unit Notes
Object Oriented Programming All Unit NotesObject Oriented Programming All Unit Notes
Object Oriented Programming All Unit Notes
BalamuruganV28
 

Similar a AOP (20)

Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
 
Spring aop
Spring aopSpring aop
Spring aop
 
Spring aop
Spring aopSpring aop
Spring aop
 
Spring aop concepts
Spring aop conceptsSpring aop concepts
Spring aop concepts
 
Spring framework AOP
Spring framework  AOPSpring framework  AOP
Spring framework AOP
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
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 fundamentals
Spring fundamentalsSpring fundamentals
Spring fundamentals
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perl
 
Spring from a to Z
Spring from  a to ZSpring from  a to Z
Spring from a to Z
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
Spring 1 day program
Spring 1 day programSpring 1 day program
Spring 1 day program
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, android
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
МАКСИМ БАРВІНСЬКИЙ «AspectJ in Test Automation.» Lviv QA Day 2019
МАКСИМ БАРВІНСЬКИЙ «AspectJ in Test Automation.»  Lviv QA Day 2019МАКСИМ БАРВІНСЬКИЙ «AspectJ in Test Automation.»  Lviv QA Day 2019
МАКСИМ БАРВІНСЬКИЙ «AspectJ in Test Automation.» Lviv QA Day 2019
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Object Oriented Programming All Unit Notes
Object Oriented Programming All Unit NotesObject Oriented Programming All Unit Notes
Object Oriented Programming All Unit Notes
 

Más de Joshua Yoon (6)

Data access
Data accessData access
Data access
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Database design
Database designDatabase design
Database design
 
HTTP Basic
HTTP BasicHTTP Basic
HTTP Basic
 
Javascript
JavascriptJavascript
Javascript
 
기업문화
기업문화기업문화
기업문화
 

Último

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Último (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 

AOP

  • 4. Aspect Oriented Programming  Gregor Kiczales Gregor Kiczales is a professor of computer science at the University of British Columbia in Canada. His best-known work is on aspect-oriented programming and the AspectJ extension for Java at Xerox PARC. Wikipedia Born: 1961 Alma mater: Massachusetts Institute of Technology Books: The Art of the Metaobject Protocol
  • 7. Aspect Oriented Programming as·pect /ˈaspekt/ noun 1. a particular part or feature of something. feature, facet, side, characteristic, particular, detail; angle, slant a specific way in which something can be considered. a particular appearance or quality. appearance, look, air, cast, mien, demeanor, expression 2. the positioning of a building or thing in a specified direction
  • 8. Aspect Oriented Programming  Aspect Oriented Programming In computing, aspect-oriented programming (AOP) is a patented programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. Wikipedia Aspect-Oriented Programming (AOP) complements Object-Oriented Programming (OOP) by providing another way of thinking about program structure. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. Aspects enable the modularization of concerns such as transaction management that cut across multiple types and objects. (Such concerns are often termed crosscutting concerns in AOP literature.) Spring framework reference
  • 9. Aspect Oriented Programming  AOP implemented languages Java AspectJ JavaScript Logtalk Lua make Matlab ML Perl PHP Prolog Python Racket Ruby Squeak Smalltalk UML 2.0 XM .NET Framework languages (C# / VB.NET) ActionScript Ada AutoHotkey C / C++ COBOL The Cocoa Objective-C frameworks ColdFusion Common Lisp Delphi Delphi Prism e (IEEE 1647) Emacs Lisp Groovy Haskell
  • 11. Aspect Oriented Programming  AOP Terminologies  Aspect: a modularization of a concern that cuts across multiple classes. Transaction management is a good example of a crosscutting concern in enterprise Java applications. In Spring AOP, aspects are implemented using regular classes (the schema-based approach) or regular classes annotated with the @Aspectannotation (the @AspectJ style).  Join point: a point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a join point alwaysrepresents a method execution.  Advice: action taken by an aspect at a particular join point. Different types of advice include "around," "before" and "after" advice. (Advice types are discussed below.) Many AOP frameworks, including Spring, model an advice as an interceptor, maintaining a chain of interceptors around the join point.  Pointcut: a predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut (for example, the execution of a method with a certain name). The concept of join points as matched by pointcut expressions is central to AOP, and Spring uses the AspectJ pointcut expression language by default.  Introduction: declaring additional methods or fields on behalf of a type. Spring AOP allows you to introduce new interfaces (and a corresponding implementation) to any advised object. For example, you could use an introduction to make a bean implement an IsModified interface, to simplify caching. (An introduction is known as an inter-type declaration in the AspectJ community.)  Target object: object being advised by one or more aspects. Also referred to as the advised object. Since Spring AOP is implemented using runtime proxies, this object will always be a proxied object.  AOP proxy: an object created by the AOP framework in order to implement the aspect contracts (advise method executions and so on). In the Spring Framework, an AOP proxy will be a JDK dynamic proxy or a CGLIB proxy.  Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime
  • 12. Aspect Oriented Programming  Types of advice  Before advice: Advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).  After returning advice: Advice to be executed after a join point completes normally: for example, if a method returns without throwing an exception.  After throwing advice: Advice to be executed if a method exits by throwing an exception.  After (finally) advice: Advice to be executed regardless of the means by which a join point exits (normal or exceptional return).  Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception.
  • 13. Aspect Oriented Programming  AOP terminology Advice injected code Join Point a point of execution Pointcut point of injection (set of Join Point) Aspect Advice + Pointcut Weaving process of injection
  • 18. Aspect Oriented Programming public interface Foo { Object bar(Object obj) throws BazException; } public class FooImpl implements Foo { Object bar(Object obj) throws BazException { // ... } } public class DebugProxy implements java.lang.reflect.InvocationHandler { private Object obj; public static Object newInstance(Object obj) { return java.lang.reflect.Proxy.newProxyInstance( obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), new DebugProxy(obj)); } private DebugProxy(Object obj) { this.obj = obj; } public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { Object result; try { System.out.println("before method " + m.getName()); result = m.invoke(obj, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } catch (Exception e) { throw new RuntimeException("unexpected invocation exception: " + e.getMessage()); } finally { System.out.println("after method " + m.getName()); } return result; } } https://docs.oracle.com/javase/8/docs/technotes/guides/reflection/proxy.html
  • 19. Aspect Oriented Programming  Code Example http://www.mkyong.com/spring/spring-aop-examples-advice/ Mobile API Cache
  • 20. Aspect Oriented Programming  AspectJ AspectJ is an aspect-oriented programming (AOP) extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source project
  • 21. Aspect Oriented Programming  Reference https://en.wikipedia.org/wiki/Aspect-oriented_programming http://docs.spring.io/spring/docs/current/spring-framework- reference/html/aop.html https://www.opencredo.com/2015/07/14/dynamic-proxies-java-part- 2/ https://en.wikipedia.org/wiki/AspectJ https://en.wikipedia.org/wiki/Spring_Framework#Aspect- oriented_programming_framework https://en.wikipedia.org/wiki/Aspect-oriented_software_development http://www.eclipse.org/aspectj/ https://www.google.com/patents/US6467086 http://java2novice.com/spring/aop-and-aspectj-introduction/