Revisiting the Strategy pattern
In this section, we leverage the Strategy pattern to compose complex object trees and use DI to dynamically create those instances without using the new
keyword, moving away from being control freaks and toward writing DI-ready code.
The Strategy pattern is a behavioral design pattern we can use to compose object trees at runtime, allowing extra flexibility and control over objects’ behavior. Composing our objects using the Strategy pattern makes our classes smaller, easier to test and maintain, and puts us on the SOLID path.
From now on, we want to compose objects and lower the amount of inheritance to a minimum. We call that principle composition over inheritance. The goal is to inject dependencies (composition) into the current class instead of depending on base class features (inheritance).
Additionally, this approach enables us to pull out behaviors and place them in separate classes, adhering to the Single Responsibility Principle...