Difference between Spring IOC and Spring AOP

前端 未结 3 938
一向
一向 2021-02-15 22:45

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

相关标签:
3条回答
  • 2021-02-15 23:15

    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)

    Since purpose of Spring AOP is to enforce certain behavior across components.So, Spring IOC comes in handy to achieve this purpose

    0 讨论(0)
  • 2021-02-15 23:27

    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

    0 讨论(0)
  • 2021-02-15 23:30

    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.

    0 讨论(0)
提交回复
热议问题