public interface BaseDAO { public void save(Object poObject); public void detacheUpdate(Object poObject); public <T>T load(Class<T> poClass, Object keyObject); public void delete(Object poObject); } import java.lang.reflect.Constructor; import java.util.HashMap; import java.util.Map; public class DAOFactory { private static final Map<String, Object> map = new HashMap<String, Object>(); private static DAOFactory instance; private DAOFactory() { } public synchronized static DAOFactory getInstance() { if (instance == null) { instance = new DAOFactory(); } return instance; } public <T extends BaseDAO> T getDAO(Class<T> daoInterfaceClass,String daoImplClassName) { final String key = daoInterfaceClass.getSimpleName(); BaseDAO dao = null; if (!map.containsKey(key)) { try { Constructor c = Class.forName(daoImplClassName).getDeclaredConstructor(new Class[]{}); c.setAccessible(true); dao = (BaseDAO) c.newInstance(new Object[] {}); map.put(key, dao); } catch (Exception ex) { throw new ExceptionInInitializerError(ex); } } return (T)dao; } }