Welcome to Shaun Luttin's public notebook. It contains rough, practical notes. The guiding idea is that, despite what marketing tells us, there are no experts at anything. Sharing our half-baked ideas helps everyone. We're all just muddling thru. Find out more about our work at bigfont.ca.

Dependency injection with and without inheritance

Tags: software-development

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