Dependency Inversion Principle (SOLID) vs Encapsulation (Pillars of OOP)

后端 未结 7 707
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 02:35

I was recently having a debate about the Dependency Inversion Principle, Inversion of Control and Dependency Injection. In relation to this topic we w

7条回答
  •  旧时难觅i
    2021-01-30 02:51

    I will try to answer your questions, According to my understanding:

    • Is IoC a direct implementation of the Dependency Inversion Principle?

      we can't label IoC as the direct implementation of DIP , as DIP focuses on making higher level modules depending on the abstraction and not on the concretion of lower level modules. But rather IoC is an implementation of Dependency Injection.

    • Does IoC always break encapsulation, and therefore OOP?

      I don't think the mechanism of IoC will violate Encapsulation. But can make the system become Tightly coupled.

    • Should IoC be used sparingly, religiously or appropriately?

      IoC can be used as a in many patterns like Bridge Pattern, where seperating Concretion from Abstraction improves the code. Thus can be used in order to achieve DIP.

    • What is the difference between IoC and an IoC container?

      IoC is a mechanism of Dependency Inversion but containers are those which uses IoC.

提交回复
热议问题