Benjamin wrote:The class can pull it's own dependencies
Same reason a class should not pull data from a global variable. Causes various code smells.
http://googletesting.blogspot.com/2008/ ... oject.html
Not only does dependency injection let you mock out the object, it lets you implement the strategy pattern. For example if every class is hard coded to a specific strategy, adding a second one would involve editing much duplicated code. Its a myth that dependency injection makes your API hard to use, you do not in practice need to pass "every" object to "every" other class. For example A car object may only get passed an Engine & Chassis object, and database object. The database object would not have to be passed to the engine object & chassis objects manually, simply passing it to the car object would cause that to happen. The important part is that if you
wanted to pass a different adapter to the engine, you could.
The reasons to do it one way VS the other, joeseazr1987, is not for performance but rather to keep the code clean. Things that are more likely to cause performance slow downs is doing inefficient operations during loops, things like that. The way you structure your code however dictates how easy it will be to develop & test within that code base. If its hard to develop, performance will be hard to get. If its easy to develop, performance will come easy.