Aspect-Oriented Programming with AspectJ

concepcionsockSoftware and s/w Development

Aug 15, 2012 (5 years and 4 months ago)

287 views

http://eclipse.org/aspectj

1
..16

aspectj tools

new and noteworthy

Mik Kersten

University of British Columbia

Adrian Colyer

IBM Hursley

OOPSLA, October 26
-
27 2004, Vancouver

http://eclipse.org/aspectj

2
..16

good modularity


socket creation in Tomcat


colored lines show relevant lines of code


fits nicely into one package (3 classes)

http://eclipse.org/aspectj

3
..16

pretty good modularity


class loading in Tomcat


colored lines show relevant lines of code


mostly in one package (9 classes)

http://eclipse.org/aspectj

4
..16

not so good modularity


logging in Tomcat


scattered across the packages and classes


error handling, security, business rules, …

http://eclipse.org/aspectj

5
..16

the cost of tangled code


redundant code


same fragment of code in many places


difficult to reason about


non
-
explicit structure


the big picture of the tangling isn’t clear


difficult to change


have to find all the code involved


and be sure to change it consistently


http://eclipse.org/aspectj

6
..16

the aop idea


crosscutting is inherent in complex systems


crosscutting concerns


have a clear purpose


have a natural structure


so, let’s capture the structure of crosscutting
concerns explicitly...


in a modular way


with linguistic and tool support

http://eclipse.org/aspectj

7
..16

The role of tool support



IDE tools make code easy to navigate


Reference structure embedded In the code


Declaration lookup


Structured search


But inheritance structure can be hard to
extract by reading code alone


Especially in large systems


E.g. who overrides this method?



http://eclipse.org/aspectj

8
..16

Join points


Key points in program execution


method & constructor execution


method & constructor call


field get & set


exception

handler

execution


static &

dynamic

initialization





Demo…

:Line

end1:Point

moveBy(int, int)

moveBy(int, int)

setX(int)

setY(int)

moveBy(int, int)

setX(int)

setY(int)

end2:Point

http://eclipse.org/aspectj

10
..16

AspectJ 1.2 tools suite


IDE plugins


AJDT for Eclipse (up to 3.0)


JBuilder (up to X)


NetBeans (
up

to 3.4.2)


Emacs


Other tools


Command line incremental compiler


Bytecode weaver


AJDoc


Ant task


AspectJ Browser


http://eclipse.org/aspectj

11
..16

Making do without AOP support


You’re already working with crosscutting
structure


J2EE’s XML descriptors, generative
programming


Structured search and refactoring tools can help


But it’s not explicit


http://eclipse.org/aspectj

12
..16

Exposing crosscutting structure


AspectJ express crosscutting directly


Direct semantics enable good tool support


Crosscutting structure is explicit


Editor, views, documentation, …



Demo: auxiliary aspects, views…


http://eclipse.org/aspectj

13
..16

AOP reduces system complexity


Aspects are a new language mechanism, so
there is a learning curve


But with good tool support AOP programs
are easier to understand than their OO
counterparts


http://eclipse.org/aspectj

14
..16

What’s next?


Java 5 support


Refactoring


Java refactorings will update aspects


AspectJ refactorings


Aspect
-
oriented refactorings will help with migration and
evolution


Structure views


Everywhere you see

OO structure you see

the corresponding

AO structure

http://eclipse.org/aspectj

15
..16

Other AOP tools


AspectJ language compilers


ajc: production, IDE integration


abc: research, optimization


XML language compilers


AspectWerkz


JBoss AOP


Spring


Joint point models, pointcuts, and advice are
the common to each of these

http://eclipse.org/aspectj

16
..16

AspectJ credits


Versions 0.1
-
1.1 developed at PARC


Eclipse.org Technology project


AspectJ team


Andy Clement, Adrian Colyer, Erik

Hilsdale, Wes Isberg and Mik Kersten


AJDT team


Matt Chapman, Andy Clement,

Adrian Colyer, Mik Kersten and

Julie Waterhouse


http://eclipse.org/aspectj



http://eclipse.org/ajdt