您的位置:首页 > 移动开发 > Android开发

android工厂类

2016-05-05 16:58 429 查看
package com.ithm.lotteryhm28.util;

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

import com.ithm.lotteryhm28.engine.UserEngine;

/**
* 工厂类
* @author Administrator
*
*/
public class BeanFactory {
// 依据配置文件加载实例

private static Properties properties;
static{
properties=new Properties();
// bean.properties必须在src的跟目录下
try {
properties.load(BeanFactory.class.getClassLoader().getResourceAsStream("bean.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* 加载需要的实现类
* @param clazz
* @return
*/
public static<T> T getImpl(Class<T> clazz)
{
String key=clazz.getSimpleName();//clazz.getName()
String className = properties.getProperty(key);
try {
return (T) Class.forName(className).newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}


UserEngine=com.sdingba.xxxx.su.impl.UserEngineImpl


UserEngine engine = BeanFactory.getImpl(UserEngine.class);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: