Aspect-Oriented Programming and Aspect-J
TDDD05 Ola Leifer
Most slides courtesy of Jens Gustafsson and Mikhail Chalabine
Aspect-Oriented Programming and Aspect-J TDDD05 Ola Leifer Most - - PowerPoint PPT Presentation
Aspect-Oriented Programming and Aspect-J TDDD05 Ola Leifer Most slides courtesy of Jens Gustafsson and Mikhail Chalabine Outline: Aspect-Oriented Programming New concepts introduced Crosscutting concern Aspect Dynamic aspect
Most slides courtesy of Jens Gustafsson and Mikhail Chalabine
2
Crosscutting concern Aspect Dynamic aspect weaving Static aspect weaving Join point Dynamic join point model Static join point model
3
Introspection Introcession
4
Data and operations combined Encapsulation Objects are self contained
5
6
7
8
User authentication Persistence Timing
Code scattering Code tangling
9
Understandability Testability
Find code Change it consistently No help from OO tools
10
From org.apache.tomcat Source fles
11
12
13
14
15
16
(code execution pattern execution modifcation)
17
18
19
Join point Pointcut Advice
20
A location in (a component) code
Example: A method or class defnition
A well-defned point in the program fow Example: A call to a method
21
The “pattern” part of a weaving rule Is a predicate that matches join points Picks out certain join points Exposes parameters at join points
The balanceAltered
22
picks out each join point that's a call to a void method defned
picks out each call to SomeClass public methods
picks out each pointcut that occurs in the dynamic context of
pointcuts in the control fow,
23
join point reached joint point matched
24
Implements join points, pointcuts, advice
25
Join points Pointcuts Advice Aspects Weaving
26
Open Source Tool integration Eclipse
27
28
29
30
31
AspectJ gives code access to some part of the context of
Methods Designators
32
State-based: this, target, args Control Flow-based: cflow, cflowbelow Class-initialization: staticinitialization Program Text-based: withincode, within Dynamic Property-based: If, adviceexecution
33
getThis() getTarget() getArgs() getSignature() getSourceLocation() getKind() toString() toShortString() toLongString()
34
35
Matches execution of a method or constructor
Matches calls to a method
Matches execution of the frst constructor
Matches exceptions
Matches the reference to a class attribute
Matches the assignment to a class attribute
36
Returns the target object of a join point
Returns the object associated with a particular join point
Exposes the arguments to a join point
37
Returns join points in the execution fow of another join
Returns join points in the execution fow of another join
Matches the execution of a class's static initialization
38
Matches within a method or a constructor
Matches within a specifc type (class)
Allows a dynamic condition to be part of a pointcut
Matches on advice join points
Matches pre-initialization join points
39
40
41
Unqualifed After returning After throwing
42
43
44
45
46
47
48
methods constructors felds
49
50
(Byte) code size reduction