Dependency injection
In the previous chapter we briefly already discussed dependency injection (DI). Now we will dig into it a bit more detail.
Objects usually do not work on their own. Most of the time the implementation depends on the services of other classes. When we want to write something to the console we use the System class. When we manage the table of guesses we need Color objects and ColorManager.
In case of writing to the console we may not realize the dependency because the class being part of the JDK class library is available all the time and all we need to do is to write System.out.println. In this case this dependency is wired into the code. We cannot send the output somewhere else unless we change the code. This is not too ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access