Dependencies need to be decoupled. Since most of our dependencies are not injected through constructors, the code has tight coupling and is not testable. We can adopt a hybrid approach: if the dependency is not provided through the constructor, create it using a private factory method. This way, we can avoid bloated constructors while achieving highly testable code.
Dependencies need to be decoupled. Since most of our dependencies are not injected through constructors, the code has tight coupling and is not testable. We can adopt a hybrid approach: if the dependency is not provided through the constructor, create it using a private factory method. This way, we can avoid bloated constructors while achieving highly testable code.