我认为这主要是基于意见的,但无论如何我都会投入2p。
我一直在做的事情是这样的问自己,什么是知识我的代码的最低金额要求,以必须做它应该做的?
如果我的代码仅使用from中的代码 Other team's library,那么我将仅包含Other team's library为依赖项。
如果我的代码也使用的代码Third-party library,那么我也将包括它。
比方说,我从以下类My Library,Other Library和Third-party Library(我会使用Java示例代码)
package mylibrary;
import otherlibrary.Bar;
public class Foo {
public void doFoo() {
Bar bar = new Bar();
bar.doBar();
}
}
在里面 Other Library
package otherlibrary;
import thirdparty.Baz;
public class Bar {
public void doBar() {
Baz baz = new Baz();
baz.doSomething();
}
}
在里面 Third-party library
package thirdparty;
public class Baz {
public void doBaz() {
System.out.println("baz");
}
}
因为我的代码Foo仅取决于中的代码otherlibrary,所以这就是我要包括的全部,因为这就是我所关心的。我不在乎otherlibrary.Bar#doBar它怎么做,我只是想要它去做。
但是,如果我们将更改为otherlibrary.Bar#doBar接受a Baz做某事,例如
public void doBar(Baz baz) {
baz.doBaz();
}
然后,我需要更改mylibrary.Foo#doFoo为类似
public void doFoo() {
Bar bar = new Bar();
Baz baz = new Baz();
bar.doBar(baz);
}
因为我现在对如何Bar#doBar做事情感兴趣,并且我的代码需要知道Baz要做我想做的事情,所以我需要明确说明所包含的库。
如果我的代码必须了解thirdparty库中的内容,那么我必须将其包括为依赖项。
尽管也许的作者Bar应该隐藏更多这些细节,所以我不需要包括thirdparty库...
thirdyparty版本4 开始并otherlibrary需要版本3 ,则依赖地狱始终是个问题。您对此有何看法?