What is Inversion of Control?

前端 未结 30 2815
清歌不尽
清歌不尽 2020-11-22 00:13

Inversion of Control (IoC) can be quite confusing when it is first encountered.

  1. What is it?
  2. Which problem does it solve?
  3. When is it appropria
30条回答
  •  甜味超标
    2020-11-22 00:19

    Suppose you are an object. And you go to a restaurant:

    Without IoC: you ask for "apple", and you are always served apple when you ask more.

    With IoC: You can ask for "fruit". You can get different fruits each time you get served. for example, apple, orange, or water melon.

    So, obviously, IoC is preferred when you like the varieties.

提交回复
热议问题