DI exists in two major variants, Constructor-based dependency injection and Setter-based dependency injection.
我的理解是,介面注入其實也是透過setter注入來實現的:
interface InjectPerson {
public void injectHere(Person p);
}
class Company implements InjectPerson {
Person injectedPerson;
public void injectHere(Person p) {
this.injectedPerson = p;
}
}
Spring的文檔上說:
我的理解是,介面注入其實也是透過setter注入來實現的: