November 2024
Intermediate to advanced
300 pages
7h 12m
English
You changed the design of AddressRetriever. Before, it created an HttpImpl instance in retrieve as a private detail. Now, a client using AddressRetriever must pass an HTTP-derived object to its constructor (or use a dependency injection tool):
| | var retriever = new AddressRetriever(new HttpImpl()); |
Changing design to simplify testing might seem odd, but doing so lets you write the tests that increase your confidence to ship.
You’re not limited to constructor injection; you can inject stubs in many other ways. Some ways require no changes to the interface of your class. You can use setters instead of constructors, you can override factory methods, you can introduce abstract factories, and you can even use ...
Read now
Unlock full access