Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Spring IOC and Spring AOP

Tags:

spring

What is the Difference between Spring IOC and Spring AOP and their Importance ?

like image 812
Sunil Rk Avatar asked Mar 28 '13 06:03

Sunil Rk


People also ask

What is Spring IoC and AOP?

Objective of Spring IOC is to reduce explicit dependencies between components, while purpose of Spring AOP is to wire components together possibly by enforcing certain common behavior (read: NOT Interface)

What is the difference between Spring container and IoC container?

An IoC container is a common characteristic of frameworks that implement IoC. In the Spring framework, the interface ApplicationContext represents the IoC container. The Spring container is responsible for instantiating, configuring and assembling objects known as beans, as well as managing their life cycles.

Is Di and IoC both are same?

Inversion of Control(IoC) is also known as Dependency injection (DI). The Spring container uses Dependency Injection (DI) to manage the components that build up an application and these objects are called Spring Beans. Spring implements DI by either an XML configuration file or annotations.

What is the use of IoC in Spring?

Spring IoC is the mechanism to achieve loose-coupling between Objects dependencies. To achieve loose coupling and dynamic binding of the objects at runtime, objects dependencies are injected by other assembler objects.


2 Answers

Have you searched the web for IoC and AOP? There are a lot of references to both.

In a nutshell, IoC allows an external force to determine what implementation will be used by code rather than the code determining the implementation. The "external force" might be a configuration file, a unit test, other different code, etc.

AOP allows cross-cutting concerns to be implemented outside of the code affected by those concerns.

The "purpose" of Spring includes IoC and AOP, but goes quite a ways beyond that in its scope.

For more details please check.

Inversion of Control Containers and the Dependency Injection pattern and Aspect-oriented programming Also check this

What is AOP, Dependency Injection and Inversion Of Control in Simple English

IoC, AOP and more

like image 141
NoNaMe Avatar answered Oct 08 '22 09:10

NoNaMe


Spring IOC: In simple answer normally you create object with new operator and set yourself for getter and setter. So, yes we use new operator in Java to create object. There is no any bad in doing this. But, when your project size grows and lots of developers are working, and you want to achieve POJO-based programming, you can use DI. So then maybe your question arises - why I can not code it myself? Of course you can use the power of reflection, annotation, and XML. But, some other had already coded this then why not reuse the third party one? There are lots of options for you to choose; Spring can be the best one. It manages your object life cycle from object creation to its destruction. You use the objects created and set by Spring DI container but you do not create them yourself.

Spring AOP: It is related to cross cutting concern. What it mean is in large system the common functionality is scattered throughout different modules. So AOP provides an easiest way to take out a common implementation in the form of 'aspect'. You can also in this case write own implementation using proxy concept but you can reuse the code of proxy based that is implementation of APO alliance using Spring.

like image 43
abishkar bhattarai Avatar answered Oct 08 '22 07:10

abishkar bhattarai