What is IOC and DI?

Answer

  1. public class Employee{  
  2. Address address;  
  3. Employee(){  
  4. address=new Address();//creating instance  
  5. }  
  6. }  

Now, there is dependency between Employee and Address because Employee is forced to use the same address instance.

Let's write the IOC or DI code.

 
  1. public class Employee{  
  2. Address address;  
  3. Employee(Address address){  
  4. this.address=address;//not creating instance  
  5. }  
  6. }  

Now, there is no dependency between Employee and Address because Employee is not forced to use the same address instance. It can use any address instance.

All spring Questions

Ask your interview questions on spring

Write Your comment or Questions if you want the answers on spring from spring Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---