Summary
This chapter covered the basics of Dependency Injection and how to leverage it to follow the Dependency Inversion Principle helped by the Inversion of Control principle. We then revisited the Strategy design pattern, and saw how to use it to create a flexible, DI-ready system. We also revisited the Singleton pattern, seeing that we can inject the same instance, system-wide, by using the singleton lifetime when configuring dependencies in the container. We finally saw how to leverage factories to handle complex object creation logic.
We also talked about moving code around, the illusion of improvement, and the cost of engineering. We saw that the new
keyword could help reduce complexity when the construction logic is simple enough and that it could save time and money. On the other hand, we also explored a few techniques to handle object creation complexity to create maintainable and testable programs, such as factories, and get away from the Control Freak code smell. We...