Thursday, September 28, 2023

How Spring is different from core java

 Mostly Spring differs from Core java has it reduces dependency of one element on other. In spring the code is made loosely coupled and hence dependency on one element on other is completely eliminated.

With the help of dependency injection (dependency is injected through annotations or xml). Code is made loosely coupled. For good programming practice, the code should be loosely coupled. Which in core java, we cannot do. It can be done in spring.


For Example

Class Employee{

private String empID=null;

private Address add=null;


public String getEmpId(){

return empID;}

public void setEmpId(String empID){

this.empID=empID;}

public Address getAddress(){

return add;}

public void setAddress(Address add){

this.add=add;}




}

Class Address{

}

In the above example Class Employee depends on Class Address in Core Java. The example is said to be tightly coupled code. In spring Injection of Class Address is either done by .xml file or annotation. Hence the dependency is reduced, and code is made loosely coupled. 


No comments:

Post a Comment