This is mostly opinion-based I think, but I'll put in my 2p anyway.
The way I've always done it is by asking myself, what's the minimum amount of knowledge my code needs to have to do what its supposed to do?
If my code only uses code from Other team's library
, then I will only include Other team's library
as a dependency.
If my code also uses code from Third-party library
, then I will include it as well.
Let's say I had the following classes from My Library
, Other Library
, and Third-party Library
(I'll use Java for the example code)
package mylibrary;
import otherlibrary.Bar;
public class Foo {
public void doFoo() {
Bar bar = new Bar();
bar.doBar();
}
}
In the Other Library
package otherlibrary;
import thirdparty.Baz;
public class Bar {
public void doBar() {
Baz baz = new Baz();
baz.doSomething();
}
}
In the Third-party library
package thirdparty;
public class Baz {
public void doBaz() {
System.out.println("baz");
}
}
Because my code in Foo
only depends on code from otherlibrary
, that's all I would include, because that's all I care about. I don't care how otherlibrary.Bar#doBar
does whatever it does, I just want it to do it.
If however, we changed the otherlibrary.Bar#doBar
to accept a Baz
to do something with, like
public void doBar(Baz baz) {
baz.doBaz();
}
I would then need to change mylibrary.Foo#doFoo
to something like
public void doFoo() {
Bar bar = new Bar();
Baz baz = new Baz();
bar.doBar(baz);
}
Because I am now interested in how Bar#doBar
is going to do its thing, and my code needs to know about Baz
to do what I want it to do, I need to be explicit about the libraries I include.
If my code must know about stuff within the thirdparty
library, then I must include it as a dependency.
Although perhaps the author of Bar
should hide away more of those details so I don't need to include the thirdparty
library...