pect Oriented Programming - PowerPoint PPT Presentation

1 / 52
About This Presentation
Title:

pect Oriented Programming

Description:

volution of software programming methodology. Direct machine-level coding. Structured programming ... volution of software programming methodology. Object ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 53
Provided by: mahmou6
Category:

less

Transcript and Presenter's Notes

Title: pect Oriented Programming


1
pect Oriented Programming
AOP
S
A
  • hinking on the level of Concerns

T
2
GENDA
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

3
volution of software programming methodology
E
AOP
  • Direct machine-level coding
  • Structured programming
  • Object Oriented Programming
  • Aspect Oriented Programming

4
volution of software programming methodology
E
AOP
  • Direct machine-level coding

00110101011001100110011011100010110010011001101110
0000
Thinking about the machines instruction set more
than the problem it self
5
volution of software programming methodology
E
AOP
  • Structured programming

Algorithm A
Algorithm B
DS B
Input
Design the Algorithm then Design the Data
DS C
Algorithm D
Algorithm C
DS D
Output
6
volution 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
7
volution 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
8
GENDA
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

9
ystem Crosscutting concerns
S
AOP
  • Concern

A particular goal, concept, or area of interest
10
ystem Crosscutting concerns
S
AOP
  • Crosscutting Concerns

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
11
ystem Crosscutting concerns
S
AOP
  • Crosscutting Concerns Problems

Poor traceability Lower productivity Less code
reuse Poor code quality More difficult
evolution
12
ystem Crosscutting concerns
S
AOP
  • Crosscutting Concerns Problems

Current Responses
13
ystem Crosscutting concerns
S
AOP
  • Crosscutting Concerns Problems

The architect's dilemma
14
GENDA
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

15
undamentals 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.
16
undamentals of AOP
F
AOP
  • AOP Development Steps

Final System
Aspectual Recomposition
Aspectual Decomposition
Aspects
Concerns Implementation
1
2
3
17
undamentals of AOP
F
AOP
  • AOP Development Steps

Example
CreditCardProcessor
System Concerns
Logging
1 - Aspectual Decomposition
18
undamentals of AOP
F
AOP
  • AOP Development Steps

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
19
undamentals of AOP
F
AOP
  • AOP Development Steps

Example
CreditCardProcessor
  • Log each public operation's beginning
  • Log each public operation's completion

weaving rules
Logging
Final System
3 - Aspectual Recomposition
20
undamentals of AOP
F
AOP
  • AOP Development Steps

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
21
GENDA
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

22
natomy of AOP languages
A
AOP
  • The AOP language specification
  • AOP language implementation

23
natomy 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

24
natomy 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
25
GENDA
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

26
OP benefits
A
AOP
  • Modularized implementation of crosscutting
    concerns
  • Easier-to-evolve systems
  • Late binding of design decisions
  • More code reuse

27
OP benefits
A
AOP
  • Modularized implementation of crosscutting
    concerns

Logging
Auth.
Module A
Security
Security
Logging
Auth.
Assembling Rules
System Modules
With AOP
Without AOP
28
OP benefits
A
AOP
  • Easier-to-evolve systems

To Add New Feature
New Feature
Logging
Auth.
Module A
Security
Security
Logging
Auth.
New Feat.
Assembling Rules
System Modules
Without AOP
With AOP
29
OP 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
30
OP benefits
A
AOP
  • More code reuse

Pure Module Logic
Security
Module Logic
Module Logic
Auth.
Logging
With AOP
Without AOP
31
GENDA
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

32
spectJ 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
33
GENDA
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

34
spectJ Language Overview
A
AOP
  • Joinpoints

int x getXValue() if(x gt 10) print(X gt
10) else print(X lt 10)
Points in a program's execution
35
spectJ Language Overview
A
AOP
  • Pointcuts

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)
36
spectJ Language Overview
A
AOP
  • Advice

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
37
spectJ Language Overview
A
AOP
  • Aspect

Pointcut
Advice
Weaving Rule

Pointcut Pointcut Pointcut Pointcut ...
Advice Advice Advice Advice ...

ASPECT
38
GENDA
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

39
spectJ language concepts and constructs
A
AOP
  • Joinpoints Pointcuts

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

40
spectJ language concepts and constructs
A
AOP
  • Joinpoints Pointcuts
  • 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)
41
spectJ language concepts and constructs
A
AOP
  • Joinpoints Pointcuts
  • 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() ...
42
spectJ language concepts and constructs
A
AOP
  • Joinpoints Pointcuts
  • Read/write access to a field

Public void myMethod() int y
getY() print(y) ...
get(int MyClass.x) set(String MyClass.name)
43
spectJ language concepts and constructs
A
AOP
  • Joinpoints Pointcuts
  • Exception handler execution

Public void myMethod() try // catch()
//
handler(RemoteException) handler(IOException)
handler(CreditCard)
44
spectJ language concepts and constructs
A
AOP
  • Joinpoints Pointcuts
  • Object and class initialization execution

Class MyClass static //
staticinitialization(MyClass) Staticinitializatio
n(MyClass)
45
spectJ language concepts and constructs
A
AOP
  • Advices

AspectJ provides three ways to associate an
advice with a joinpoint
Before
Joinpoint
Around
After
46
spectJ language concepts and constructs
A
AOP
  • Advices

Before
before() call(public MyClass.(..))
        System.out.println("Before "
thisJoinPoint " " System.currentTimeMillis(
))
47
spectJ language concepts and constructs
A
AOP
  • Advices

After
after() call(public MyClass.(..))
        System.out.println("After "
thisJoinPoint " " System.currentTimeMillis(
))
48
spectJ language concepts and constructs
A
AOP
  • Advices

Around
void around(Connection conn) call(Connection.clo
se()) target(conn)     if
(enablePooling)         connectionPool.put(conn)
     else         proceed()    
49
spectJ language concepts and constructs
A
AOP
  • Aspects

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() 
   
50
spectJ language concepts and constructs
A
AOP
  • Aspects

public aspect DatabaseAuthenticationAspect
    extends AbstractAuthenticationAspect
    public pointcut operationsNeeddingAuthentic
ation()        call( DatabaseServer.connect())

51
eferences
R
AOP
  • I want my AOP! By Ramnivas Laddad
  • Introduction to Aspect-Oriented Programming By
    Graham O'Regan

52
uestions
Q
AOP
?
Write a Comment
User Comments (0)
About PowerShow.com