Title: Towards A Better Organization of Programs with Aspect-Oriented Programming
1Towards A Better Organization of Programs
withAspect-Oriented Programming
- Karl Lieberherr
- Demeter Research Group
2Overview
- Aspect-Oriented Programming (AOP) Crosscuting
concerns, controlling tangling and scattering. - Example 3 concerns Find undefined entities.
- Tools for AOP
- AspectJ from Xerox PARC
- DJ from Northeastern
- Adaptive Programming and AOP
- Summary
3The MIT Technology Review Ten (Jan./Feb. 2001
issue)
- Ten emerging technologies that will change the
world - Untangling Code - Aspect-Oriented Programming
(AOP) - Data Mining
- Micro Fluids
- Robot Design
- ...
4Northeastern Connection
- Crista Lopes wrote the first Ph.D. Thesis on AOP
at Northeastern supported by Xerox PARC. - The Demeter Research Group worked with
interesting AOP Systems long before the name AOP
was invented.
5Quote MIT Technology Magazine
- The idea of aspects has been around for many
years and with many different names. It is called
adaptive programming at Northeastern University,
and subject-oriented programming at IBM,
6AOP
- Crosscutting concerns
- Example Logging record every operation an
application performs - When adding a new operation to this application,
always put a trace statement in - Keeping track of crosscutting concerns is
error-prone
7AOP
- Crosscutting concerns, when implemented in an
ad-hoc way, lead to a lot of tangling and
scattering in the program. - Goal of AOP is to control the tangling and
scattering in the program.
8Tangling count color changes
ordinary program
better program
structure-shy functionality
Components
structure
Aspect 1
synchronization
Aspect 2
9Scattering count number of modules to which
color goes
ordinary program
better program
structure-shy functionality
M1
Components
structure
Aspect 1
M2
M3
synchronization
Aspect 2
10Aspect-Oriented ProgrammingExample
- Separating the following cross-cutting concerns
- Object Structure
- Traversals through Objects
- Advice on Traversals
- Focus on those three concerns only. They appear
frequently.
11Why crosscutting?
overall graph object structure green graph
traversal purple advice
r0
BusList
Route1BusRoute
buses
busStops
BusStopList
Bus15DieselPowered
passengers
CentralSquareBusStop
waiting
PersonList
PersonList
JoanPerson
PaulPerson
SeemaPerson
EricPerson
r
r
12Keeping Track
- When object structure changes at certain places,
need to update traversal. - Error prone.
13Why aspects Oblivious
- Object Structure
- does not have to know about traversals and advice
on traversals - Traversals
- dont have to know about advice on traversals
- Advice on Traversals
- has to know minimally about object structure and
traversals
14Ad-hoc Implementationof three concerns
- Leads to lots of tangled and scattered code with
numerous disadvantages - The question is not how to eliminate the tangling
but how to reduce it - AOP is about tangling control of the
implementation of crosscutting concerns - Crosscutting will always lead to some tangling at
code level
15Example
- Check whether all used entities are defined.
- Object structure, traversal, advice on traversal
16Find undefined things
definedThings
System
Thing
usedThings
UsedThingsHolder
definedThings from System bypassing
UsedThingsHolder to Thing usedThings from
System through UsedThingsHolder to Thing
17Name map
18Java Program with less tangling
- class Cd_graph
- String vi from Vertex to edu.neu.ccs.demeter.
Ident - void isDefined(ClassGraph cg)
- checkDefined(cg, getClasses(cg))
- HashSet getClasses(ClassGraph cg)
- String definedThings
- "from Cd_graph bypassing Neighbors to
Vertex" - Visitor v new Visitor()
- HashSet return_val new HashSet()
- void before(Vertex v1)
- return_val.add(cg.fetch(v1, vi) )
- public Object getReturnValue()return
return_val - cg.traverse(this, definedThings, v)
- return (HashSet)v.getReturnValue()
-
green traversal black bold structure purple
advice red parameters
19Java Program with less tangling
- void checkDefined(ClassGraph cg, final HashSet
classHash) - String usedThings
- from Cd_graph through Neighbors to
Vertex" - cg.traverse(this, usedThings, new Visitor()
- void before(Vertex v) Ident vn cg.fetch(v,
vi) - if (!classHash.contains(vn))
- System.out.println("The object "
vn - " is undefined.")
- )
-
20Tangling is localized
- Instead of having code spread across several
classes, it is localized in one class. - Java program is describing the abstract pattern
behind the computation of interest checking
whether used entities are defined. - Tangling control through abstraction of patterns.
21UML class diagram ClassG
definedThings from ClassG bypassing Body to
ClassName
Entry
0..
EParse
entries
ClassG
BParse
ClassDef
Body
Part
parts
className
0..
ClassName
Concrete
Abstract
22UML class diagram ClassG
usedThings from ClassG through Body to ClassName
Entry
0..
EParse
entries
ClassG
BParse
ClassDef
Body
Part
parts
className
0..
ClassName
Concrete
Abstract
23Equation System
usedThings from EquationSystem through
Expression to Variable
Example x 1.0 . y ( x 4.0). z ( x y).
EquationSystem ltequationsgt List(Equation). Equat
ion ltlhsgt Variable ltrhsgt Expression
.. Variable Ident. Expression Simple
Compound. Simple Variable Numerical. Compound
( Op ltargsgt List(Expression) ). Op Add
Mul. Add . Mul . Numerical float.
24Equation System
definedThings from EquationSystem bypassing
Expression to Variable
Example x 1.0 . y ( x 4.0). z ( x y).
EquationSystem ltequationsgt List(Equation). Equat
ion ltlhsgt Variable ltrhsgt Expression
.. Variable Ident. Expression Simple
Compound. Simple Variable Numerical. Compound
( Op ltargsgt List(Expression) ). Op Add
Mul. Add . Mul . Numerical float.
25AspectJ (Xerox PARC)
- A general aspect-oriented programming language
for Java. - An aspect is like a class and may contain
pointcut definitions defining a set of join
points and advice saying what to do before, after
or instead of the join points.
26DJ (Northeastern)
- Is a Java package that supports AOP for the three
concerns class structure, traversals, and
traversal advice. - Connection to AspectJ both can be used
simultaneously. - DJ provides an implementation of Adaptive
Programming (AP).
27Principle behind AP Polyas Inventor Paradox
- Polya observed that it is often easier to solve a
more general problem than the one at hand and
then to use the solution of the general problem
to solve the specific problem. The hard work
consists of finding the appropriate
generalization. - Programs become shorter and more powerful. A
paradox. With less work we achieve more.
28Apply Polya to Programming
- Generalization Dont write the program for a
specific data structure, write it for an abstract
data structure.
29Concepts needed(DJ classes)
- ClassGraph
- Strategy
- ObjectGraph
- ObjectGraphSlice
- Visitor
30Adaptive Programming
Strategy
Bold names refer to DJ classes.
is use-case based abstraction of
ClassGraph
defines family of
ObjectGraph
31Adaptive Programming
Strategy
defines traversals of
ObjectGraph
plus Strategy defines
ObjectGraphSlice
32Adaptive Programming
Strategy
guides and informs
Visitor
33AspectJ (Xerox) DJ (NEU)
- Abstract pointcut
- set of execution points
- where to watch
- Advice
- what to do
- Concrete pointcut
- set notation using regular expressions
- Abstract object slice
- set of entry/exit points
- where to go
- Visitor
- what to do
- Actual object slice
- traversal strategies
34AOP AP
- Program with aspects that correspond to the
concerns of the programmer.
- Relieve the programmer from the details of some
concern. - Create robustness to changes in an aspect.
- AP is about join point reduction.
- Example structure-shyness
35Technology Evolution
Object-Oriented Programming
Tangled structure/behaviors robustness to
structure changes
Other Technologies
Adaptive Programming
Tangled concerns in general (synchronization,
etc.)
Aspect-Oriented Programming
robustness to aspect changes
Aspect-Oriented Programming II
36Benefits of Adaptive Programming
- robustness to changes
- shorter programs
- design matches program,
- more understandable code
- partially automated evolution
- keep all benefits of OO technology
- improved productivity
Applicable to design and documentation of your
current systems.
37Summary
- AOP getting a lot of attention. Addresses an
important problem how to program crosscutting
concerns. - AP is about relieving the programmer from the
details of a concern traditionally from the
structural concern. - Want to learn more Take COM 3360 Adaptive
Object-Oriented Software Development and attend
the Demeter Seminar.
38Current Work
- DARPA grant with BBN (Prof. Wand, Lieberherr) on
AOP for real-time systems. - Doug Orleans PhD thesis, in progress Design and
Implementation of Aspect-Oriented Languages. - Johan Ovlinger PhD thesis, in progress The
Collaboration/Adapter Approach to AOP. Works with
industry SKYVA.
39Critical Mass
- Professors Lorenz, Wand, Lieberherr, Clinger
- Ph.D. students Orleans, Ovlinger, Wu
- Masters students working on JSR 31 project
Prasenijt Adak, Huichan He - Undergraduate student Jon Kelley
- Courses COM 3360 (graduate), COM 1205
(undergraduate)