学习笔记:泛型工厂

用在dao层 和 service层的解耦的泛型工厂:

public class DaoFactory {

	private DaoFactory(){}
	private static final DaoFactory instance = new DaoFactory();
	public static DaoFactory getInstance(){
		return instance;
	}
	
	public  T createDao(String className,Class clazz){
		try{
			return (T)Class.forName(className).newInstance();
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}	
}



你可能感兴趣的:(javaWeb)