Do we achieve Dependency Inversion Principle using Dependency Injection technique?
开发者_运维知识库Do we achieve Dependency Inversion Principle using Dependency Injection technique?
Am I correct?
Yes. Dependency inversion says “do not seek your dependencies yourself, they will be supplied to you.” Dependency injection is a way of supplying the dependencies to the object from the outside.
yes it is
The Dependency Inversion Principle in two sentences:
High level modules should not depend upon low level modules. Both should depend upon abstractions.
and
Abstractions should not depend upon details. Details should depend upon abstractions.
while
The Dependency Injection Pattern is one of the concrete solutions to the application/code composition problem. And yes this solution is implementation of the Dependency Inversion Principle. Probably the most known place to read is Martin Fowler - Inversion of Control Containers and the Dependency Injection pattern.
精彩评论