这一节,将创建一个工厂类,通过依赖注入实现控制反转,哈哈,逐渐接近spring思想了有木有?开整。
---------------------------------------------------------------------------------------------------------------------------------------
package com.michael.spring;
/**
* @ClassName: HelloWorldFactory
* @Description: TODO(工厂类)
* @author huangbin 876301469@qq.com
* @date 2014-4-2 下午9:23:23
*
*/
public class HelloWorldFactory {
public static HelloWorldStr getFileHelloWorld(){
IHelloWorld fileHello = new FileHelloWorld("helloworld.properties");
HelloWorldStr helloStr = new HelloWorldStr(fileHello);
return helloStr;
}
}
--------------------------------------------------------------------------------------------------------------------------------------
将接口暴露给用户,将控制权留给用户
--------------------------------------------------------------------------------------------------------------------------------------
package com.michael.spring;
/**
* @ClassName: HelloWorldClient
* @Description: TODO(客户端调用)
* @author huangbin 876301469@qq.com
* @date 2014-4-2 下午8:48:28
*
*/
public class HelloWorldClient {
public static void main(String[] args) {
HelloWorldStr heloStr = HelloWorldFactory.getFileHelloWorld();
System.out.println(heloStr.getContent());
}
}
-------------------------------------------------------------------------------------------------------------------------------------