go to  ForumEasy.com   
JavaPro  
 
 
   Home  |  MyForum  |  FAQ  |  Archive    You are not logged in. [Login] or [Register]  
Forum Home » Web Design & Implementation » Inverse of Control (IoC) & Dependency Injection (DI)
Email To Friend  |   Set Alert To This Topic Rewarding Points Availabe: 0 (What's this) New Topic  |   Post Reply
Author Topic: Inverse of Control (IoC) & Dependency Injection (DI)
WebSpider
member
offline   
 
posts: 147
joined: 06/29/2006
from: Seattle, WA
  posted on: 10/20/2019 09:26:48 PM    Edit  |   Quote  |   Report 
Inverse of Control (IoC) & Dependency Injection (DI)

Inversion of Control (IoC) is the principle where the control flow of a program is inverted: instead of the programmer controlling the flow of a program, the external sources (framework, services, other components) take control of it. It's like we plug something into something else.

Without IoC, the flow is for object to call certain library and expect certain results returned; with IoC, a framework is controlling the flow by predefined interfaces -- all job left for developers is just to provide the customized implementations (or plugins) for those interfaces according to specific needs. The developers do not (or even need to) know when and how those plugins are called. A good example is the Spring MVC Framework.


Dependency Injection (DI) is a form of IoC -- the dependency of an object is inverted: instead it controls its own dependencies, life cycle, the object only USE the dependencies which are injected from external sources (framework, services, other components).

Just like in coding, we seldom hard-code the value of STRING but we rely on the configuration to provide the flexibility or usability of our software product. A good example is the Database URL STRING.

Move one step further from variable STRING to class OBJECT -- instead of hard-coding the OBJECT we usually build business or service logic on interfaces and rely on the injections for flexibility.

 Profile | Reply Points Earned: 0

 
Powered by ForumEasy © 2003-2005, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.