samedi 30 septembre 2017

Does dependency injection mean no inline initialization?

If I follow dependency injection principle for a class design, I should make sure my class does not try to instantiate its dependencies within my class, but rather ask for the object through the constructor.

This way I am in control of the dependencies I provide for the class while unit-testing it. This I understand.

But what I am not sure is does this mean that a good class design which follows dependency injection principle means that its fields should never be initialized inline? Should we totally avoid inline initialization to produce testable code?

Aucun commentaire:

Enregistrer un commentaire