Dependency injection with and without inheritance
Dependency injection is valuable in languages that lack inheritance and becomes more powerful in languages that have inheritance.
-
Without inheritance, dependency injection lets the container control constructor arguments . "Resolve for me an object of type
Carrot
and use whatever constructor arguments you would like when creating that object." -
With inheritance, dependency injection lets the container also control implementation . "Resolve for me an object of type
IVegetable
and use whatever implementation and/or constructor arguments you would like."
Related: http://stackoverflow.com/q/39885560/1108891