I have a class hierarchy, where, say, class ICommon is at the root. I have separate repositories implementations in order to manipulate objects belonging at each level in this hierarchy.
interface IRepository<T extends ICommon> {
public void createOrUpdate(T toCreate);
}
Now, I want to maintain a Map of classes VS their repositories. Its this part which I can't figure out.
I tried this, which works, but I do not think it is the correct representation.
private Map<Class<? extends ICommon>, IRepository<? extends ICommon>> repoMap = new
HashMap<Class<? extends ICommon>, IRepository<? extends ICommon>>();
Later on, clients call this method to get an appropriate repository instance.
public <T extends ICommon> IRepository<T> getRepository(Class<T> clazz) {
return (IRepository<T>) repoMap.get(clazz);
}