-
PRESENTER: In this lecture, you will learn what AOP is.
-
AOP stands for Aspect-Oriented Programming.
-
This can be best understood by looking at
-
an enterprise application which is typically divided into layers:
-
UI layer, business logic layer,
-
data access layer, and many more.
-
All these layers typically have
-
some non-functional requirements like security, profiling,
-
logging, transaction management when we are especially using a database or a MQ system.
-
Logging to write our errors or information to the log files,
-
profiling to see how our application is performing,
-
and security, you know what it is for.
-
These are called cross-cutting concerns because these are required across
-
these layers as well as across
-
the applications in our enterprise or even another enterprise.
-
Any application we develop will need all these and more.
-
That is where aspects come in and Aspect-Oriented Programming comes in.
-
In object-oriented world, we define a class
-
and object is the key unit that are present in that class.
-
In the aspect-oriented world,
-
an aspect is the key unit.
-
You can think of it as a specialized class
-
that addresses one of these cross-cutting concerns.
-
It could be security,
-
profiling, logging, transaction management, etc.
-
These aspects can be applied to our classes and objects at runtime.
-
Doing that, will have several advantages.
-
Number 1, cross-cutting concerns, as I already said.
-
We can address all the non-functional requirements which are
-
common across the enterprise or even enterprises,
-
allowing us to reuse.
-
Once we develop an aspect,
-
we can apply it across classes in our application and across applications.
-
Quick development, we can focus on our business logic without
-
worrying about the non-functional requirements because we already
-
have the aspects and we can apply them or we can
-
create an aspect later on and we can apply it.
-
Focus on one aspect.
-
Using this, we can specialize. A particular developer if
-
he is interested in working on security aspect,
-
you can develop an aspect for that.
-
Another developer can work on logging,
-
transaction management, etc, which will allow specialization.
-
Finally, a powerful feature is enabling and disabling aspects at runtime.
-
We can enable them and we can disable them
-
using configuration if we don't need them anymore.
-
There are several popular frameworks in the open-source.
-
Java will do implement Aspect-Oriented Programming.
-
Spring and aspect here are two popular ones.
-
Spring also works together with
-
AspectJ and it has its own implementation of aspects as well.