In computing, aspect-oriented programming is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns.
10. Modularity
AOP introduces aspects, which encapsulate behaviors
that affect multiple classes into reusable modules.
Exist in isolated and encapsulated constructs
Be attached to almost any standard code construct
Be transported between projects
10
11. Cross-Cutting Concern
Concern:
a concern is a particular set of information that has an effect
on the code of a computer program.
Cross-Cutting Concern:
the necessary concern “cuts across” many different classes
and methods
aspects of a program that affect other concerns. These
concerns often cannot be cleanly decomposed from the rest of
the system in both the design and implementation.
11
17. Aspectual Decomposition
In the first step, the requirements are decomposed to
identify crosscutting and common concerns. Here, the
core concerns are separated from the crosscutting
system level concerns.
17
19. Aspectual Re-composition
In the last step, an aspect integrator specifies re-
composition rules by creating modularization units
(aspects). The re-composition process is also called
weaving or integrating.
19
22. Terminology
Join point
Place where behavior can be added
A join point is a well-defined point in the program flow
Advice
Code that can be injected at join points
Advice is a code that is executed at a point-cut
Point cut
A point cut is a group of join points
Aspect
Container holding point cuts and advice
An aspect is a module for handling crosscutting concerns
Aspects are reusable and inheritable
Weaving
Combines advices with point cuts
22
24. 24
AspectJ
AspectJ is a small, well-integrated extension to Java
Based on the 1997 PhD thesis by Christina Lopes, A
Language Framework for Distributed Programming
AspectJ modularizes crosscutting concerns
That is, code for one aspect of the program (such as tracing) is
collected together in one place
The AspectJ compiler is free and open source
AspectJ works with JBuilder, Forté, Eclipse, probably
others
Best online write-up:
http://www.eclipse.org/aspectj/
Parts of this lecture were taken from the above paper
26. 26
The Figure Element Example
A point-cut named move that chooses various method calls:
pointcut move():
call(void FigureElement.setXY(int,int)) ||
call(void Point.setX(int)) ||
call(void Point.setY(int)) ||
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point));
Advice (code) that runs before the move point-cut:
before(): move() {
System.out.println("About to move");
}
Advice that runs after the move point-cut:
after(): move() {
System.out.println("Just successfully moved");
}
28. Decorator pattern
Intent
The decorator pattern can be used to extend (decorate) the functionality of a certain
object statically, or in some cases at run-time, independently of other instances of
the same class, provided some groundwork is done at design time.
Dynamically adds responsibility to the interface by wrapping the original code
Motivation
As an example, consider a window in a windowing system. To
allow scrolling of the window's contents, one may wish to add
horizontal or vertical scrollbars to it, as appropriate.
Usage
A decorator makes it possible to add or alter behavior of an
interface at run-time
28
32. AOP disadvantage
As AOP is a new technology, it is not very well tested
and documented.
32
33. Conclusions
Aspect-Oriented Programming introduces a new way of
handling crosscutting concerns.
It is hard to predict what AOP will become in the future,
but one thing is clear, AOP will be part of future
programming paradigms.
33