Spring:使用动态工厂降低耦合度

创建接口:

public interface ISomeInterface {

void doSome();

}

创建接口实现类:

public class SomeServiceIm implements ISomeInterface {

@Override

public void doSome() {

// TODO Auto-generated method stub

System.out.println("执行dosomg方法!!!");

}

}

创建工厂类:

public class SomeFactory {

public ISomeInterface getSomeSericeIm(){

return new SomeServiceIm();

}

}

容器配置:

<bean id="factory" class="com.abc.Beans.SomeFactory"/>

<bean id="someservice" factory-bean="factory" factory-method="getSomeSericeIm"/>

Spring:使用动态工厂降低耦合度

工厂类及其配置全解

Spring:使用动态工厂降低耦合度

测试类

Spring:使用动态工厂降低耦合度

结果