Wednesday, June 18, 2008

What is AOP Aspect Oriented Programming ?

generally definition of AOP is modularizing the cross-cutting concerns.

each module main concern is to provide services for its particular domain.
The common object-oriented technique for reusing common functionality is through inheritance or delegation.
But inheritance can lead to a brittle object hierarchy if the same base class is used throughout an application, and delegation can be cumbersome and still
requires duplicated calls to the delegate object.

AOP is an alternative, With
AOP, you still define the common functionality in one place, but you can declaratively
define how and where this functionality is applied without having to modify
the class to which you are applying the new feature.Cross-cutting concerns can
now be modularized into special objects called aspects.
This has two benefits.
1. the logic for each concern is now in one place, as opposed to being scattered all
over the code base.ex. logging.
2. our service modules are now cleaner since they only
contain code for their core functionality and secondary concerns have been
moved to aspects.ex. student, course module.

An aspect is the cross-cutting functionality you are implementing. It is the aspect,
or area, of your application you are modularizing. The most common (albeit simple)
example of an aspect is logging. Logging is something that is required
throughout an application. However, because applications tend to be broken
down into layers based on functionality, reusing a logging module through inheritance
does not make sense. However, you can create a logging aspect and apply it
throughout your application using AOP.
A joinpoint is a point in the execution of the application where an aspect can be
plugged in. This point could be a method being called, an exception being
thrown, or even a field being modified. These are the points where your aspect’s
code can be inserted into the normal flow of your application to add new behavior.
Adviceis the actual implementation of Aspect..It is advising ur application of new behaviour.
In our Logging example, the logging advice would contain the
code that implements the actual logging, such as writing to a log file. Advice is
inserted into our application at joinpoints.
A pointcut defines at what joinpoint the advice should be applied. Advice can be applied at any joinpoint supported by AOP framework.
These pointcuts will tell where is the advice to be applied .
You can specify these pointcuts using an explicit class or method names or through regular expressions
that define matching class and method name patterns.Some AOP frameworks
allow you to create dynamic pointcuts that determine whether to apply advice
based on runtime decisions, such as the value of method parameters.
Introductionallows you to add new methods or attributes to the existing classes.
TargetA target is the class that is being advised.

Note: the above information i got it from the Manning in Action Series : Spring ebook and some other books

No comments: