01-11-2016, 03:23 PM
1463068291-aopsomreport.docx (Size: 95.8 KB / Downloads: 4)
. Introduction
As global digitalization and the size of applications expand at an exponential rate,
software engineering complexities are also growing. One feature of this complexity is the
repetition of functionality such as security, memory management, resource sharing, and error and
failure handling throughout an application. To address this issue, software researchers are
developing methodologies based on a new programming element: the aspect.
Aspect Oriented Programming is a mindset: a new programming methodology involving the
aspects.
2. History
AOP as such has a number of antecedents: the Visitor Design Pattern, CLOS MOP, and
others]. AspectJ (perhaps the most popular general-purpose AOP package) was created by
Gregor Kiczales and colleagues at Xerox PARC and made available in 2001. IBM's research
team emphasized the continuity of the practice of modularizing concerns with past programming
practice, and offered the more powerful (but less usable) Hyper/J and Concern Manipulation
Environment, which have not seen wide usage.
3. Introducing concerns, cross-cutting concerns, Aspects & AOP
Concerns
The part of the software that is relevant to a particular concept, goal or purpose.
We can view a complex software system as a combined implementation of multiple concerns. A
typical system may consist of several kinds of concerns, including business logic, performance,
data persistence, logging and debugging, authentication, security, multithread safety, error
checking, and so on. There are also development-process concerns, such as comprehensibility,
maintainability, traceability, and evolution ease.
.
DEPT OF CSE,SDMCET, DHARWAD
Graphical illustration of a system as a set of concerns implemented by various modules
Cross-cutting concerns
In this, the methods used for different concerns intersect. Hence crosscutting concerns span over
multiple implementation modules.
Although crosscutting concerns span over many modules, current implementation techniques
tend to implement these requirements concentrating mainly on the core module
implementation
Aspect-oriented programming (AOP)
Is a new technology for separation of
name Aspect Oriented Programming was coined by Chris Maeder of Xerox Paleo Alto research
Centre.
Aspect Oriented Programming revolves around the three functions
• Identify concerns that cut across
• Write code (an aspect) that encapsulates that concern
• Define a weave that specifies how the aspect will be weaved into existing code
Aspect Oriented Programming
crosscutting concerns into single units called aspects
class / object boundaries
5
module- level
aspects. The
Aspect Oriented Programming
6
Aspects
An aspect is a modular unit of crosscutting implementation. It encapsulates behaviors
that affect multiple classes into reusable modules. An aspect is a piece of code that describes a
recurring property of a program.
Applications can, have multiple aspects. Aspects provide crosscutting modularity. In
other words, programmers can use aspects to create software modules for issues that cut across
various parts of an application. Aspect modules do not stand on their own; they function only as
add-on code that developers can weave into applications.
Why use AOP?
It provides the pluggable way to dynamically add the additional concern before, after or around the actual logic. Suppose there are 10 methods in a class as given below:
1. class A{
2. public void m1(){...}
3. public void m2(){...}
4. public void m3(){...}
5. public void m4(){...}
6. public void m5(){...}
7. public void n1(){...}
8. public void n2(){...}
9. public void p1(){...}
10. public void p2(){...}
11. public void p3(){...}
12. }
1. class A{
2. public void m1(){...}
3. public void m2(){...}
4. public void m3(){...}
5. public void m4(){...}
6. public void m5(){...}
7. public void n1(){...}
8. public void n2(){...}
9. public void p1(){...}
10. public void p2(){...}
11. public void p3(){...}
12. }
There are 5 methods that starts from m, 2 methods that starts from n and 3 methods that starts from p.
Understanding Scenario I have to maintain log and send notification after calling methods that starts from m.
Problem without AOP We can call methods (that maintains log and sends notification) from the methods starting with m. In such scenario, we need to write the code in all the 5 methods.
But, if client says in future, I don't have to send notification, you need to change all the methods. It leads to the maintenance problem.
Solution with AOP We don't have to call methods from the method. Now we can define the additional concern like maintaining log, sending notification etc. in the method of a class. Its entry is given in the xml file.
In future, if client says to remove the notifier functionality, we need to change only in the xml file. So, maintenance is easy in AOP.
________________________________________
Where use AOP?
AOP is mostly used in following cases:
• to provide declarative enterprise services such as declarative transaction management.
• It allows users to implement custom aspects.
________________________________________
AOP Concepts and Terminology
AOP concepts and terminologies are as follows:
• Join point
• Advice
• Pointcut
• Introduction
• Target Object
• Aspect
• Interceptor
• AOP Proxy
• Weaving
________________________________________
Join point
Join point is any point in your program such as method execution, exception handling, field access etc. Spring supports only method execution join point.
________________________________________
Advice
Advice represents an action taken by an aspect at a particular join point. There are different types of advices:
• Before Advice: it executes before a join point.
• After Returning Advice: it executes after a joint point completes normally.
• After Throwing Advice: it executes if method exits by throwing an exception.
• After (finally) Advice: it executes after a join point regardless of join point exit whether normally or exceptional return.
• Around Advice: It executes before and after a join point.
________________________________________
Pointcut
It is an expression language of AOP that matches join points.
________________________________________
Introduction
It means introduction of additional method and fields for a type. It allows you to introduce new interface to any advised object.
________________________________________
Target Object
It is the object i.e. being advised by one or more aspects. It is also known as proxied object in spring because Spring AOP is implemented using runtime proxies.
________________________________________
Aspect
It is a class that contains advices, joinpoints etc.
________________________________________
Interceptor
It is an aspect that contains only one advice.
________________________________________
AOP Proxy
It is used to implement aspect contracts, created by AOP framework. It will be a JDK dynamic proxy or CGLIB proxy in spring framework.
________________________________________
Weaving
It is the process of linking aspect with other application types or objects to create an advised object. Weaving can be done at compile time, load time or runtime. Spring AOP performs weaving at runtime.
________________________________________
AOP Implementations
AOP implementations are provided by:
1. AspectJ
2. Spring AOP
3. JBoss AOP