The core aspects of Spring framework is InversionOfControl and Dependency Injection.
What is exactly inversion of control?
Inversion of control is the principle where the control flow of a program is inverted: instead the programmer controls the flow of a program; the external sources (framework, services, and other components like container) take control of it.
Let’s take an example:
-
1. If an instance of the servlet does not exist, the web container.
a. Loads the servlet class.
b. Creates an instance of the servlet class.
c. Initializes the servlet instance by calling the init method.
- 2. Invokes the service method, passing request and response objects.
- 3. If the container needs to remove the servlet, it finalizes the servlet by calling the servlet’s destroy method.
What is dependency injection?
Dependency Injection is a design pattern on which dependency of object is injected by framework rather than created by Object itself.
Lets rewind my previous example, assume you have student servlet, your servlet needs request object to get the request parameters like student details from html page, now my question is who is giving request object to your servlet? Obviously servlet container, this means your servlet is depends on request object that has been injected by the container servlet.
Inversion-of-Control (IOC) is simply the Dependency-Injection (DI) design pattern for loose coupling between business logic implementations.
Dependency injection is alternative for Inversion of control. Check this link Click here
Thank you.
Keep regular posting. Good luck.
ReplyDelete