What is the dependency inversion principle and why is it important?

前端 未结 15 1105
别那么骄傲
别那么骄傲 2020-11-28 00:06

What is the dependency inversion principle and why is it important?

15条回答
  •  Happy的楠姐
    2020-11-28 00:59

    Good answers and good examples are already given by others here.

    The reason DIP is important is because it ensures the OO-principle "loosely coupled design".

    The objects in your software should NOT get into a hierarchy where some objects are the top-level ones, dependent on low-level objects. Changes in low-level objects will then ripple-through to your top-level objects which makes the software very fragile for change.

    You want your 'top-level' objects to be very stable and not fragile for change, therefore you need to invert the dependencies.

提交回复
热议问题