控制反转(Inversion of Control,缩写为IoC),是面向对象编程中的一种设计原则,可以用来减低计算机代码之间的耦合度。
一、原始方法需要设置beanfactory
测试类
/**
* 模拟表现层,用于调用业务层
*/
public class Client {
public static void main(String[] args) {
/*IAccountService accountService = new AccountServiceImpl();*/
for (int i = 0; i < 5; i++) {
IAccountService as = (IAccountService) BeanFactory.getBean("accountService");
System.out.println(as);
as.saveAccount();
}
}
}
BeanFactory工厂类
public class BeanFac