There is also another way to solve the above problem known as Service Location, which we will get to shortly.
ISomeDependencyyou would have to change this source code
ISomeDependencywe no longer have any of the above problems. Something so simple as just passing in a dependency rather than creating it yourself can be one of the largest steps taken towards a better design, and this approach is often referred to as the Hollywood Principle because of the "Don't call us, we'll call you" approach.
Imagine you have an
IPathfinderinterface and you decide to make an
AStarPathfinderimplementation and its ok, your path finding calls are quick enough but take up a lot of memory for larger maps. You then make an
OptimizedAStarPathfinder, you can now use this implementation throughout your entier codebase without changing a line of code within the classes which consume it when using IoC
Just because this may seem too much of a hassle having to manually set each dependency in the constructor it is well worth it once we build upon this and get into Composition and Unit Testing topics, as this is the pre-requisite to being able to achieve them.