Title: pect Oriented Programming
1pect Oriented Programming
AOP
S
A
- hinking on the level of Concerns
T
2GENDA
A
AOP
- Evolution of software programming methodology
- System Crosscutting concerns
- Fundamentals of AOP
- Anatomy of AOP languages
- AOP benefits
- AspectJ overview
- AspectJ Language Overview
- AspectJ language concepts and constructs
3volution of software programming methodology
E
AOP
- Direct machine-level coding
- Structured programming
- Object Oriented Programming
- Aspect Oriented Programming
4volution of software programming methodology
E
AOP
- Direct machine-level coding
00110101011001100110011011100010110010011001101110
0000
Thinking about the machines instruction set more
than the problem it self
5volution of software programming methodology
E
AOP
Algorithm A
Algorithm B
DS B
Input
Design the Algorithm then Design the Data
DS C
Algorithm D
Algorithm C
DS D
Output
6volution of software programming methodology
E
AOP
- Object Oriented Programming
Object A
Object C
Object B
A set of objects that interact with each other
Object F
Object E
Object G
Object D
7volution of software programming methodology
E
AOP
- Aspect Oriented Programming
Crosscutting Concern A
Crosscutting Concern B
Crosscutting Concern C
Crosscutting Concern D
View the system as a set of concerns
Weaver
End System
8GENDA
A
AOP
- Evolution of software programming methodology
- System Crosscutting concerns
- Fundamentals of AOP
- Anatomy of AOP languages
- AOP benefits
- AspectJ overview
- AspectJ Language Overview
- AspectJ language concepts and constructs
9ystem Crosscutting concerns
S
AOP
A particular goal, concept, or area of interest
10ystem Crosscutting concerns
S
AOP
Crosscutting concerns
System Level Requirements
System level requirements that crosscut many core
module level requirements
Logging
Security
Authen.
Analyze
Module A
Module B
Module C
Requirements
Core Module Level Requirements
11ystem Crosscutting concerns
S
AOP
- Crosscutting Concerns Problems
Poor traceability Lower productivity Less code
reuse Poor code quality More difficult
evolution
12ystem Crosscutting concerns
S
AOP
- Crosscutting Concerns Problems
Current Responses
13ystem Crosscutting concerns
S
AOP
- Crosscutting Concerns Problems
The architect's dilemma
14GENDA
A
AOP
- Evolution of software programming methodology
- System Crosscutting concerns
- Fundamentals of AOP
- Anatomy of AOP languages
- AOP benefits
- AspectJ overview
- AspectJ Language Overview
- AspectJ language concepts and constructs
15undamentals of AOP
F
AOP
- Aspect Oriented Programming
Orthogonal Concerns
lets you implement individual concerns in a
loosely coupled fashion, and combine these
implementations to form the final system.
16undamentals of AOP
F
AOP
Final System
Aspectual Recomposition
Aspectual Decomposition
Aspects
Concerns Implementation
1
2
3
17undamentals of AOP
F
AOP
Example
CreditCardProcessor
System Concerns
Logging
1 - Aspectual Decomposition
18undamentals of AOP
F
AOP
Example
public class CreditCardProcessor public
void credit(CreditCard card,Currency amount)
throws InvalidCardException // logic
public interface Logger public void
log(String message)
2 - Concerns Implementation
19undamentals of AOP
F
AOP
Example
CreditCardProcessor
- Log each public operation's beginning
- Log each public operation's completion
weaving rules
Logging
Final System
3 - Aspectual Recomposition
20undamentals of AOP
F
AOP
Example
public class CreditCardProcessor Logger
logger public void credit(CreditCard
card,Currency amount) throws InvalidCardExceptio
n logger.log("Starting CreditCardProcessor.
credit(CreditCard,Money) "
"Card " card " Amount " amount) //
Crediting logic logger.log("Completing
CreditCardProcessor.credit(CreditCard,Money) "
"Card " card "
Amount " amount)
Final System
21GENDA
A
AOP
- Evolution of software programming methodology
- System Crosscutting concerns
- Fundamentals of AOP
- Anatomy of AOP languages
- AOP benefits
- AspectJ overview
- AspectJ Language Overview
- AspectJ language concepts and constructs
22natomy of AOP languages
A
AOP
- The AOP language specification
- AOP language implementation
23natomy of AOP languages
A
AOP
- The AOP language specification
Describes language constructs and syntax
Implementation of concerns
Weaving rules specification
public class CreditCardProcessor public
void credit(
- Log each public operation's beginning
- Log each public
24natomy of AOP languages
A
AOP
- AOP language implementation
- Combine the individual concerns
- Convert the resulting information into executable
code
Source-to-Source Translation
VM Implementation
25GENDA
A
AOP
- Evolution of software programming methodology
- System Crosscutting concerns
- Fundamentals of AOP
- Anatomy of AOP languages
- AOP benefits
- AspectJ overview
- AspectJ Language Overview
- AspectJ language concepts and constructs
26OP benefits
A
AOP
- Modularized implementation of crosscutting
concerns - Easier-to-evolve systems
- Late binding of design decisions
- More code reuse
27OP benefits
A
AOP
- Modularized implementation of crosscutting
concerns
Logging
Auth.
Module A
Security
Security
Logging
Auth.
Assembling Rules
System Modules
With AOP
Without AOP
28OP benefits
A
AOP
To Add New Feature
New Feature
Logging
Auth.
Module A
Security
Security
Logging
Auth.
New Feat.
Assembling Rules
System Modules
Without AOP
With AOP
29OP benefits
A
AOP
- Late binding of design decisions
Module E
Module A
Module B
Module F
Module A
Module B
Expected Module
Expected Module
Expected Module
With AOP
Without AOP
30OP benefits
A
AOP
Pure Module Logic
Security
Module Logic
Module Logic
Auth.
Logging
With AOP
Without AOP
31GENDA
A
AOP
- Evolution of software programming methodology
- System Crosscutting concerns
- Fundamentals of AOP
- Anatomy of AOP languages
- AOP benefits
- AspectJ overview
- AspectJ Language Overview
- AspectJ language concepts and constructs
32spectJ overview
A
AOP
AspectJ is a language specification as well as an
AOP language implementation.
AspectJ's language constructs extend the Java
programming language
provides an aspect weaver in the form of a
compiler
33GENDA
A
AOP
- Evolution of software programming methodology
- System Crosscutting concerns
- Fundamentals of AOP
- Anatomy of AOP languages
- AOP benefits
- AspectJ overview
- AspectJ Language Overview
- AspectJ language concepts and constructs
34spectJ Language Overview
A
AOP
int x getXValue() if(x gt 10) print(X gt
10) else print(X lt 10)
Points in a program's execution
35spectJ Language Overview
A
AOP
At if(x gt 10) collect x
Program constructs to designate joinpoints and
collect specific context at those points
int x getXValue() if(x gt 10) print(X gt
10) else print(X lt 10)
36spectJ Language Overview
A
AOP
Code that runs upon meeting certain conditions
At if(x gt 10) collect x
int x getXValue() if(x gt 10) print(X gt
10) else print(X lt 10)
Print(X x)
Advice
37spectJ Language Overview
A
AOP
Pointcut
Advice
Weaving Rule
Pointcut Pointcut Pointcut Pointcut ...
Advice Advice Advice Advice ...
ASPECT
38GENDA
A
AOP
- Evolution of software programming methodology
- System Crosscutting concerns
- Fundamentals of AOP
- Anatomy of AOP languages
- AOP benefits
- AspectJ overview
- AspectJ Language Overview
- AspectJ language concepts and constructs
39spectJ language concepts and constructs
A
AOP
AspectJ makes the following pointcuts available
- Method call and execution
- Constructor call and execution
- Read/write access to a field
- Exception handler execution
- Object and class initialization execution
40spectJ language concepts and constructs
A
AOP
- Method call and execution
Call(public void MyClass.myMethod(String))
Call(MyClass.new()) Call(MyClass.new()) Call
( MyClass.myMethod())
int x 10 MyClass.myMethod(Hello) if(x lt 10)
41spectJ language concepts and constructs
A
AOP
- Constructor call and execution
execution(public void MyClass.myMethod(String)) e
xecution( MyClass.myMethod(..)) execution(publi
c com.mycompany...(..)) execution(MyClass.n
ew(..))
Public void myMethod() ...
42spectJ language concepts and constructs
A
AOP
- Read/write access to a field
Public void myMethod() int y
getY() print(y) ...
get(int MyClass.x) set(String MyClass.name)
43spectJ language concepts and constructs
A
AOP
- Exception handler execution
Public void myMethod() try // catch()
//
handler(RemoteException) handler(IOException)
handler(CreditCard)
44spectJ language concepts and constructs
A
AOP
- Object and class initialization execution
Class MyClass static //
staticinitialization(MyClass) Staticinitializatio
n(MyClass)
45spectJ language concepts and constructs
A
AOP
AspectJ provides three ways to associate an
advice with a joinpoint
Before
Joinpoint
Around
After
46spectJ language concepts and constructs
A
AOP
Before
before() call(public MyClass.(..))
System.out.println("Before "
thisJoinPoint " " System.currentTimeMillis(
))
47spectJ language concepts and constructs
A
AOP
After
after() call(public MyClass.(..))
System.out.println("After "
thisJoinPoint " " System.currentTimeMillis(
))
48spectJ language concepts and constructs
A
AOP
Around
void around(Connection conn) call(Connection.clo
se()) target(conn) if
(enablePooling) connectionPool.put(conn)
else proceed()
49spectJ language concepts and constructs
A
AOP
public abstract aspect AbstractAuthenticationAspec
t public abstract pointcut
operationsNeeddingAuthentication() befor
e() operationsNeeddingAuthentication()
// Perform authentication. If it could
not be // authenticated, let the exception
thrown by // authenticate
propagate. Authenticator.authenticate()
50spectJ language concepts and constructs
A
AOP
public aspect DatabaseAuthenticationAspect
extends AbstractAuthenticationAspect
public pointcut operationsNeeddingAuthentic
ation() call( DatabaseServer.connect())
51eferences
R
AOP
- I want my AOP! By Ramnivas Laddad
- Introduction to Aspect-Oriented Programming By
Graham O'Regan
52uestions
Q
AOP
?