Though DI in interface driven…I am still not clear as to what exactly differentiates this from basic overloading concept. Any C# examples would be helpful.
EDIT : I read here the reason for my question
that StreamReader can be seen as example of IoC/DI…how is this different totally from overloading? Or is it just semblance to DI and not entirely DI?
They’re completely different concepts.
Overloading: providing multiples methods with the same name (or constructors) that differ by the number and/or type of parameters.
Dependency Injection: giving components all the services they need to work with (e.g. authenticators, database connections etc) rather than letting them construct these dependencies themselves. DI encourages a clean separation between interfaces and implementation, and makes unit testing much easier (as you can mock/fake dependencies).
EDIT: I don’t think I’d usually use
StreamReaderas a good example of dependency injection – in particular, it can create its own streams for you if you only specify a filename. Arguably the overloads with aStreamparameter are effectively allowing the stream dependency to be injected, but it’s not what I’d normally consider as DI. The constructor is certainly an example of overloading – but the two are really unrelated.Normally I’d think of DI in terms of services – things like authenticators, or potentially the next service in a chain (where a request goes through multiple stages, for example).