game-programming-patterns
game-programming-patterns copied to clipboard
Confusing mix of terms, service locator vs dependency injection
First, thanks for the great resource, I often use it to refresh my memory, and to help explain patterns to my coleagues.
In the chapter on the service locator pattern, there's a box out section, linking the approach to DI:
'Normally, the locator would be responsible for constructing that instance itself. Dependency injection instead says that outside code is responsible for injecting that dependency into the object that needs it.'
So far so good, but then the following example isn't DI, 'The static getAudio() function does the locating,' I.e the dependency isn't being injected, the consumer is coupled to the locators interface for getting its audio object.
I'm not sure if you've confused the concepts, (as per http://stackoverflow.com/questions/1557781/whats-the-difference-between-the-dependency-injection-and-service-locator-patte And http://blog.ircmaxell.com/2012/08/object-scoping-triste-against-service.html), or are trying to highlight the difference, but perhaps it could be made clearer?
Thanks!