This is the first article I participated in beginners’ introduction

What exactly is IOC?

Inversion of Control. Literally, inversion of control. Control transferred from programmer to framework is a programming style or programming principle. My current understanding, mainly for decoupling, is to reduce the work of the business developer (CURD engineer) and allow the business developer to focus on the development of the business as a function implementation.

The common implementation of IOC

At present, the understanding of this part is still to be improved, just look at the teacher introduced in the course, there are several ways to achieve. In the spring framework, find the relevant implementation code and post it to the forum for discussion.

  1. Rely on to find
  2. Dependency injection
  3. Template method pattern

What is the difference between IOC and DI

As mentioned above, IOC is a programming principle of inversion of control, and DI (Depedency Injection dependency Injection) is an implementation of inversion of control.

Dependency injection can be implemented in the following ways:

  1. Constructor injection
public class A{ private final B b; public A(B b){ this.b = b; } public void C(){ b.c(); }}Copy the code
  1. Setter function injection
public class A{ private B b; public void setB(B b){ this.b = b; }}Copy the code
  1. Properties into
public class A{ @Autowired private B b; public void C(){ b.c(); }}Copy the code

It can be found that no matter what kind of injection method is, the control is transferred to another class, which can be abstractly summarized as class A is an epitome of the framework process, and class B is an entrance that the framework leaves the concrete implementation to us programmers.

Why didn’t I understand IOC and DI before

I have summarized the following points:

  1. My English is not good. I can’t spell IOC and DI
  2. I don’t delve into it. I just know that people say Spring is an IOC framework. Actually I asked a lot of my colleagues (Curd engineers) and no one really understood.

Write to future self

I hope that in the future, I can insist on writing some blogs to precipitate my own technology and share and discuss technology with everyone in the forum. More than code ~