I'm implementing a simple GenericDAO
as below, but I feel like I'm doing something wrong, it works but I feel like there's something wrong anyway, could you help me?
I created an interface like this:
public interface GenericDAO<T, ID> {
public List<T> listaTodos(Class<T> clazz);
public List<T> listaComLimite(Class<T> clazz, Integer limite);
public T porId(Class<T> clazz, ID id);
public void adiciona(T t);
public T grava(T t);
public void remove(Class<T> clazz, ID id);
}
Then I created another interface (more specific), that is with what is not generic, but how can we see this extends
of GenericDAO
previous:
public interface TestDAO extends GenericDAO<Test, Long> {
public Test buscaPorNome(String nome);
}
Below I'm testing how it would look:
public void getTest(){
Test teste = testDAO.porId(Test.class, id);
}
It sounds like bullshit, but when I've extended GenericDAO
I've already passed the target class:
extends GenericDAO<Test, Long>
The question is, why should I use it again when I'm going to use it?
Test teste = testDAO.porId(Test.class, id);
Does not that sound wrong?