package Creational.AbstractFactory;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by ProdigalWang on 2017/7/26.
 */
public class CarFactory {

    private static String carType;

    private static String className = "Creational.AbstractFactory.";

    private static Properties pp = new Properties();

    static {

        try {
            pp.load(CarFactory.class.getClassLoader().getResourceAsStream("factory.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 这个时候我们需要创建不同的汽车对象时只需要修改配置文件即可。
     *
     * @return
     */
    public static Car creatCar() {
        Car car = null;

        carType = pp.getProperty("carType");

        try {
            Class clazz = Class.forName(className + carType);

            car = (Car) clazz.getConstructor().newInstance();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return car;
    }

}
