We all know dependency injection makes packages decoupled. But I'm a little confused about best practices of dependency injection in go.
Lets assume package User needs to access Config package We can pass a Config object to User methods in this way I can change the Config package functionality as long as the new code resolve the interfaces. Another approach is call Config package methods directly , but in these scenario I can change Config code too as long as the methods names remains the same. Like so Config package:
func foo() string {
return "foo"
}
After changing beneath code of Config package:
func foo() string {
return "bar"
}
Wich one is best practice in go and why ?
Aucun commentaire:
Enregistrer un commentaire