首页 > Linux操作系统 > Linux操作系统 > 怎么样理解依赖注入?
public class Person{
public boolean makeCall(long number){
Mobile mobile=new Mobile();
return mobile.dialUp(number);
}
}
public Interface MobileInterface{
public boolean dialUp(long number);
}
public class Person{
private MobileInterface mobileInterface;
public boolean makeCall(long number){
return this.mobileInterface.dialUp(number);
}
public void setMobileInterface(MobileInterface mobileInterface){
this.mobileInterface=mobileInterface;
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/13270562/viewspace-217879/ ,如需转载,请注明出处,否则将追究法律责任。