samedi 23 septembre 2017

Is too many Dependency are good for a class

While implementing a functionality in my project (mostly legacy code). I came across a design problem. Currently a class A contain 5 dependency inside the constructor. but I need one more dependency to support my functionality.

But I have read somewhere that a class should not contain more than 3 dependency.

So I decided instead of passing dependency, I called it directly (make the method static), in that case I don't need any extra dependency inside my Class A. This would work for me. but my Unit test case sucks in that case because there is no way to mock static method inside mocking framework which i am using.

Can any one help me out what approach should I need to follow.

Aucun commentaire:

Enregistrer un commentaire