Core Module is the heart of Spring, tight coupling and loose coupling is the heart concept of Core Module. We are going to learn about to tight and loose coupling between java object in spring.
Let us see loose coupling between java objects.
In order to over come tight coupling between objects, spring framework uses dependency injection mechanism with the help of POJO model and through dependency injectionits possible to achieve loose coupling
In the above example Run , Car are tightly coupled. If we want to achieve loose coupling between the objects Run and Car, we need to re-write the application like
In above example, spring container will inject either Car object or Bike object into the Run by calling setter method, So if Car object is replaced with Bike then no changes are required in Traveler class, this means there is loose coupling between Run and Vehicle object. Actually setter method will be activated through xml file.