Manu Goel Anshul Jain Ankit Gupta Honey Kumar: 1 Tuesday, August 1, 2017
Manu Goel Anshul Jain Ankit Gupta Honey Kumar: 1 Tuesday, August 1, 2017
ANSHUL JAIN
ANKIT GUPTA
HONEY KUMAR
2
Aspect Oriented Programming
AOP is about modularizing crosscutting concerns
badly modularized
without AOP with AOP
4
Terminology
Cross-cutting concerns are parts of a program which rely
on or must affect many other parts of the system
A join point is a well-defined point in the program flow
A pointcut is a group of join points
Advice is code that is executed at a pointcut
Introduction modifies the members of a class and the
relationships between classes
An aspect is a module for handling crosscutting concerns
Aspects are defined in terms of pointcuts, advice, and
introduction
Aspects are reusable and inheritable
5
Example
void main()
{int a,b,c;
float d; Now imagine similar code in
cin>>a; every method
cin>>b;
cin>>c;
try { if((a-b)!=0) { d=c/(a-b);
cout<<"Result is:"<<d; }
else { throw(a-b); }
}
catch(int i) { cout<<"Answer is infinite because a-b is:"<<i; }
6
Consequences of Crosscutting Code
Redundant code
Same fragment of code in many places
Difficult to reason about
Non-explicit structure
The big picture of the tangling isnt clear
Difficult to change
Have to find all the code involved...
...and be sure to change it consistently
...and be sure not to break it by accident
7
Aspects
In AOP crosscutting concerns are implemented in
aspects instead of fusing them into core modules.
Aspects are an additional unit of modularity.
Aspects can be reused.
By reducing code tangling it makes it easier to
understand what the core functionality of a
module is.
An aspect weaver takes the aspects and the core
modules and composes the final system.
8
Aspects in Some Common Problems
APPLICATION GP LANGUAGE COMPONENTS ASPECTS
10
Pointcuts
pointcut is a set of join points
allows a programmer to describe where and when
additional code should be executed in addition to an
already defined behaviour
This permits the addition of aspects to existing
software, or the design of software with a
clear separation of concerns, wherein the
programmer weaves (merges) different aspects into a
complete application
11
Advice
class of functions which modify other functions when
the latter are run
certain function, method or procedure that is to be
applied at a given join point of a program
term advice goes back to the term advising as
introduced by Warren Teitelman in his PhD thesis in
1966
"Advising" found its way into BBN Lisp and later
into Xerox PARC's Interlisp
12
Introduction*
An introduction is a member of an aspect, but it
defines or modifies a member of another type (class).
With introduction we can
add methods to an existing class
add fields to an existing class
extend an existing class with another
implement an interface in an existing class
convert checked exceptions into unchecked exceptions
15
AspectJ Example
public class Example {
before() : helloPC() {
System.out.print("Hello! ");
}
after() : helloPC() {
System.out.println("The message has been delivered.");
}
}
16
Open Issues
AOP is a young idea
The current status of AOP is much like that of
OOP twenty years ago
As AOP is still in research, quantitative assessment
of AOP not done till date
Very little support available
..and many more may come out after all rules
are totally established.
17
Conclusion
Aspect-oriented programming (AOP) is a new
paradigm--a new way to think about programming
not the perfect solution to the issues involved in
programming, but is a good starting point
With experience, you should be able to fine tune the
concepts of AOP to better fit your own work environment
AOP is somewhat similar to event handling, where the
events are defined outside the code itself
Like all new technologies, AOP may--or may not--
catch on in a big way
18
References
http://www.codeproject.com/Articles/4039/Aspect-
Oriented-Programming-Aspect-Oriented-Softwa
http://en.wikipedia.org/wiki/Aspect-
oriented_programming
http://www.aspectc.org/
cseweb.ucsd.edu/~wgg/CSE218/aop-ecoop97.pdf
and many more
19
Any Questions
20