Segue o exemplo para expor minha dúvida.
Minhas classes de serviço tem 4 operações básicas:
-remover
-salvar
-buscar por id
-listar
Tenho 2 objetos persistentes:
-Cliente
-Produto
É NECESSÁRIO A CRIAÇÃO de 2 interfaces? como segue exemplo abaixo:
public interface ClienteService {
void remove(Cliente cliente) throws Exception;
Cliente save(Cliente cliente) throws Exception;
Cliente findById(Cliente cliente) throws Exception;
List<Cliente> getListAll() throws Exception;
}
e
public interface ProdutoService {
void remove(Produto produto) throws Exception;
Produto save(Produto produto) throws Exception;
Produto findById(Produto produto) throws Exception;
List<Produto> getListAll() throws Exception;
}
ou o certo é usar apenas uma interface para todas as classes de serviço? como no exemplo abaixo:
[code]
public interface Service {
void remove(Object objeto) throws Exception;
Object save(Object objeto) throws Exception;
Object findById(Object objeto) throws Exception;
List<Class> getListAll() throws Exception;
}[/code]
Se puderem me esclarecer, pois as vezes vejo por ae várias interfaces q fazem a mesma coisa, e que talvez até tenham algum motivo especifico para isto mas que eu não sei qual, entretanto eu acho mais rápido e prático uma interface genérica pra todos os DAOs, e para todos os SERVICEs, e os métodos específicos viriam na implementação da interface como no exemplo abaixo:
[code]
public class ClienteServiceImpl implements Service {
@Override
public void remove(Object objeto) throws Exception {
// TODO Auto-generated method stub
}
@Override
public Object save(Object objeto) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public Object findById(Object objeto) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Class> getListAll() throws Exception {
// TODO Auto-generated method stub
return null;
}
//METODO ESPECIFICO DA IMPLEMENTACO DO SERVICE USUARIO
public List<Cliente> getListPorNome(String nome) throws Exception {
return null;
}
}[/code]
E
[code]
public class ProdutoServiceImpl implements Service {
@Override
public void remove(Object objeto) throws Exception {
// TODO Auto-generated method stub
}
@Override
public Object save(Object objeto) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public Object findById(Object objeto) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public List<Class> getListAll() throws Exception {
// TODO Auto-generated method stub
return null;
}
//METODO ESPECIFICO DA IMPLEMENTACO DO SERVICE PRODUTO
public List<Produto> getListProdutosEmFalta() throws Exception {
return null;
}
}[/code]
Se puderem esclarecer qual é a maneira mais certa de se usar!