Java Login


Hello guys, is for Java and J2EE developers, all examples are simple and easy to understand 

It is developed and maintained by Vaibhav Sharma. The views expressed on this website are his own and do not necessarily reflect the views of his former, current or future employers. I am professional Web development. I work for an IT company as Senior Consultant. Primary I write about spring, hibernate and web-services. I am trying to present here new technologies.

     << Previous
Next >>     

Aspect Oriented Programming

AOP stands for Aspect Oriented Programing. Aspect Oriented Programing complements or enhances or improves Object Oriented Programming by providing another way of thinking about program structure. The key unit of modularity in Object Oriented Programming is the class whereas in Aspect Oriented Programing the unit of modularity is the aspect. Aspects enable the modularization of crosscutting concerns.

AOP is a programming technique that allows programmers to modularize crosscutting concerns, or behavior that cuts across the typical divisions of responsibility, such as logging and transaction management. The core construct of AOP is the aspect, which encapsulates behaviors affecting multiple classes into reusable modules.

About usefulness of AOP

Let's take a look at a the following situations:

Scenario A
You are software developer in a bank. The bank has a pretty working operational system. The business is running smoothly. Government emits a policy which enforces banks to commit on some sort of transparency. Whenever money goes in or out of the bank it should be logged. The government publicly said that this is a first measure towards transparency but that more is to be expected.

Scenario B
Your web application has been released to test team. All functional tests passed but the application failed at load testing. A non-functional requirement stated that no page should take more than 500 ms to process on the server. After analysis there are dozens of queries made to the database that could be avoided by caching the results.

Scenario C
You have spent the last 2 years modeling your domain model in a perfect library consisting of 200+ classes. Lately you've been told that a new application front-end will be written and this guy needs to bind your objects to the UI. But to facilitate that task all your classes should now implement INotifyPropertyChanged.


Before we delve too deeply into AOP, let's introduce some standard terminology to help us understand the concepts.

Cross-cutting concerns: Even though most classes in an OO model will perform a single, specific function, they often share common, secondary requirements with other classes. For example, we may want to add logging to classes within the data-access layer and also to classes in the UI layer whenever a thread enters or exits a method. Even though the primary functionality of each class is very different, the code needed to perform the secondary functionality is often identical.

Advice: This is the additional code that you want to apply to your existing model. In our example, this is the logging code that we want to apply whenever the thread enters or exits a method.

Point-cut: This is the term given to the point of execution in the application at which cross-cutting concern needs to be applied. In our example, a point-cut is reached when the thread enters a method, and another point-cut is reached when the thread exits the method.

Aspect:The combination of the point-cut and the advice is termed an aspect. In next tutorials, we add a logging aspect to our application by defining a point-cut and giving the correct advice.

  • An aspect represent the cross-cutting functionality name, remember just name only.
  • One real time service required for a business logic is called one Aspect.
  • Aspect denotes only the cross-cutting functionality name not its implementation and all.

There are many other facets of AOP, such as introductions (where interfaces/methods/fields can be added to existing classes), that hold tremendous potential for developers, but I'll stick with some of simpler facets in this article. When you are familiar with the concepts presented here, I would recommend that you continue to investigate AOP and see how the other facets may be of use to you in your development environment.

     << Previous
Next >>