Dependency Injection vs. Aspect Oriented Programming in Spring

Dependency Injection (DI)

  • The technology that Spring is most identified with is the Dependency Injection (DI).
  • Dependency Injection is the heart of Spring Framework.
  • The Inversion of Control (IoC) is a general concept, and it can be expressed in many different ways and Dependency Injection is merely one concrete example of Inversion of Control.
  • When writing a complex Java application, application classes should be as independent as possible of other Java classes (i.e. Loose Coupled) to increase the possibility to reuse these classes and to test them independently of other classes while doing unit testing.
  • So Dependency Injection helps in joining these classes together (integrated) and same time keeping them independent (Loose Coupled).

Aspect Oriented Programming (AOP)

  • One of the key components of Spring is the Aspect oriented programming (AOP) framework.
  • The functions that span (cover) multiple points of an application are called cross-cutting concerns and these cross-cutting concerns are conceptually separate from the application's business logic.
  • The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. As DI helps you decouple your application objects from each other, AOP helps you decouple cross-cutting concerns from the objects that they affect.

No comments:

Post a Comment