How do you understand the IOC?

  java, question

RT, how do you understand the ioc? It would be best to write a demo explanation.

I tried to search, Chinese data basically confuse IoC (controlled flip) and DI (dependency injection), evenFirst answer on StackOverflowI have also made the same problem (fortunately, there are high votes against the comments below, otherwise my world view will soon be broken)

Control flip is a mode of Code reuse (note that it is not a design mode)

General (non-IoC) reuse is usually a user code calling component (any form of reused code, collectively referred to as a component in this answer). That is, the user code solves “Why it works, What to do”, the component solves “How to do”, and the logical entry is the user code.

The control flip is the component that calls the user code, that is, the component solves “Why it works, When to do”, the user code solves “What to do”, and the logical entry is the component

The following is an example of controlled flip except DI

  • The interface/virtual function component calls the interface/virtual function, specifically implemented by user code
  • The publish subscription (event) mode component triggers the event, and the user code subscribes to the event
  • Callback User Code Write Callback, Component to Call
  • Almost everything that can be called a frameworkUser code implements specific business logic at specified places, and the rest of the framework is responsible for