18-Feb-20
Aspect-Oriented
Present by: M. Hayeri, A. Hajati
Supervisor: PhD. H. Motameni
Introduction
Programming paradigm which aims to increase
modularity by allowing the separation of cross-cutting
concern
2
Content
 Example: OOP
 Solution: OOP
 Problem
 What’s wrong with OOP?
 Introduction
 Modularity
 Cross-Cutting Concern
 Scattering
 Tangling
 Example
 AOP what is *NOT*
 Development Stages
 Aspectual Decomposition
 Concern Implementation
 Aspectual Re-composition
 OOP compare with AOP
 Terminology
 Decorator pattern
 Decorator Structure
 AOP Tools
 The Figure Element example
 AOP disadvantage
 Conclusions
3
Example: OOP
4
Solution: OOP
5
Problem
6
CONCERN
O1
O2O3
Problem
 Some programming tasks cannot be neatly encapsulated
in objects
7
What’s wrong with OOP?
8
Aspect Oriented Programming
 Modularity
 Cross-Cutting Concern
9
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
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
Cross-Cutting Concern
 Scattering (code duplication) :
12
Cross-Cutting Concern
 Tangling(significant dependencies between systems):
13
Example
 Security(Authentication,…)
 Logging
 Caching
 Data Validation
 Error Detection
 ...
14
AOP what is *NOT* …
 OOP vs. AOP .Why "vs"? It is not "vs"
 A programming language dependent
 Silver bullet for all your problem
15
Development Stages
Aspect-Oriented Programming involves three different
development steps.
 Aspectual Decomposition
 Concern Implementation
 Aspectual re-composition
16
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
Concern Implementation
 In the second step of the development, each concern is
implemented separately
18
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
Development Stages
20
Development Stages
21
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
AOP Tools
 …
23
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
25
The Figure Element Example
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");
}
OOP compare with AOP
27
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
Decorator Pattern
29
Decorator Structure
30
 Decorator UML class diagram
Decorator Example Code
31
AOP disadvantage
 As AOP is a new technology, it is not very well tested
and documented.
32
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
Reference
34
https://en.wikipedia.org/wiki/Cross-cutting_concern
https://www.cis.upenn.edu/~matuszek/cit597-2003/Lectures/45-
aop-programming.ppt
www.unc.edu/~stotts/comp523/aopStotts.ppt
Gang of Four Design Patterns
35
The End

Aspect-oriented programming