aspose file tools*
The moose likes Other Application Frameworks and the fly likes What is AOP in spring framwork? and its deifferences with DI? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "What is AOP in spring framwork? and its deifferences with DI?" Watch "What is AOP in spring framwork? and its deifferences with DI?" New topic
Author

What is AOP in spring framwork? and its deifferences with DI?

Riyaz Abdul Kareem
Greenhorn

Joined: Apr 23, 2007
Posts: 11
Can anyone explain what is AOP in spring and its diferences with DI?
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
AOP (Aspected-oriented programming) and DI (Dependency Injection) are two different concepts, which happen to be two of the main concepts on and around which the Spring framework is built.
I suggest you google a bit on both to find some more references.
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by Riyaz Abdul Kareem:
Can anyone explain what is AOP in spring and its diferences with DI?


Dependency Injection (DI) is basically a programming model where object are given other objects that they depend upon. This is in contrast to a more conventional model where objects create or lookup objects that they depend upon. The downside of creating or looking up your own dependencies is that you are coupled to those dependencies and can't exist without them. With DI, however, you are given your dependencies, typically by a container. When used along with interfaces, you only know about your dependencies through their interface...you know nothing of how they are created or how they're implemented. You could be dealing with a local POJO, a remote web service, an EJB, or a mock implementation...you don't know and you don't care. As long as the object your given lives up to the requirements of its interface, you are happy.

AOP is a way of applying common functionality across multiple points in an application, without those points being aware that the functionality is being applied. A typical example of AOP is the use of declarative transactions. Without AOP, you might go to the effort of starting a transaction, performing your database work, then either committing or rolling back the transaction depending on whether or not the DB work was a success. No big deal, except that transaction management is probably not a core concern of your saveEmployeeInfo() method--the chief concern of that method is saving an employee's information. Using AOP, you can extract the transaction management functionality into an aspect, and then declaratively select places to apply it. Your saveEmployeeInfo() method now focuses solely on saving an employee's info and how no idea that it will be wrapped in an aspect that will start and then either commit or roll back a transaction.

So, in short, both DI and AOP are mechanisms for removing coupling from code. DI removes coupling between application objects, while AOP decouples application concerns.


Spring in Action - Unleash POJO power in your applications!
Modular Java - Discover the secret weapon to modularity on the Java platform!
XDoclet in Action - Your complete guide to code generation with XDoclet.
Riyaz Abdul Kareem
Greenhorn

Joined: Apr 23, 2007
Posts: 11
Hi Craig,

Great Content on DI and Aop, Thanks a lot...
I also got some idea on local POJO.
Sure will dig more on POJOS.

If i'm not wrong AOP means that its aspect oriented programming.
For example writing the logs in java classes.

Craig, Why i ask these many questions because i'm going to handle a
basic session on spring framework.

Thanks
riyaz
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by Riyaz Abdul Kareem:
Hi Craig,
Great Content on DI and Aop, Thanks a lot...
I also got some idea on local POJO.
Sure will dig more on POJOS.


Not much to dig on there, really. POJO is just "plain-old Java object". Everybody has a differing opinion on how "plain" a POJO must be to be considered a POJO, but in essence, it's an object that does not extend any class or implement any interface that isn't part of your application (or perhaps part of the JDK, but that part's debatable).


If i'm not wrong AOP means that its aspect oriented programming.
For example writing the logs in java classes.


Well, logging is only the "textbook" case for AOP. It's hardly the most powerful or most beneficial use of AOP.

As I mentioned, transactions are a much more interesting use of AOP than logging. Method-level security and caching are two more interesting uses of AOP. (BTW, Spring provides transaction aspect, Spring Security provides security aspects, and Spring Modules provides caching aspects).

Even then security, transactions, and caching are textbook cases for AOP...just more advanced textbook cases. There are some really smart folks out there who have figured out how to use AOP in even more interesting ways. My friend Ramnivas Laddad and Adrian Colyer are two folks who really get AOP. Both are on the Spring team, and Ramnivas has written "AspectJ in Action". If you get a chance to read anything they've written or hear them speak, I recommend that you do so. There's some good stuff in the "AOP @ Work" series, too: http://www-128.ibm.com/developerworks/views/java/libraryview.jsp?search_by=AOP@work:
Riyaz Abdul Kareem
Greenhorn

Joined: Apr 23, 2007
Posts: 11
Thanks Craig.

Sure i will look into this book "AspectJ in Action".
If any good resource on AOP & POJOS.
Please send it across to this mail id
rezz123@rediffmail.com

Still i'm not clear on POJOS. I just understand that
it is used as business object like EJB. If am i not wrong.

Thanks,
Riyaz
 
 
subject: What is AOP in spring framwork? and its deifferences with DI?
 
Similar Threads
Spring AOP / Spring AOP + AspectJ ?
Spring and AOP
Seam AOP
Spring AOP Vs Spring IoC/DI
AOP