3
I have 3 services with these methods in common create()
,deleteById()
,findAll()
,getById()
and update()
.
@Service
public class AutorService {create(),deleteById(),findAll(),getById(),update(), etc...}
@Service
public class GrupoService {create(),deleteById(),findAll(),getById(),update(), etc...}
@Service
public class GeneroService {create(),deleteById(),findAll(),getById(),update(), etc...}
I intend to transform them into an interface and create the implementation with the business Logic in them.
Would it be a good practice to create an interface with these common methods to then extend them? Because every time I have to keep creating these methods.
Example:
Genericservice with the methods in common
public interface GenericService<T, I extends Serializable> {
List<T> findAll();
T getById(Long id);
T create(T entity);
T update(T entity);
void deleteById(Long id);
}
Autorservice extend Genericservice and has its findByName method()
public interface AutorService extends GenericService<AutorEntity,Long>{
public AutorEntity findByNome(String nome);
}
Autorserviceimpl implements Genericservice with the Autorservice method
@Service
public class AutorServiceImpl implements AutorService {/*.....*/}
Hello @Felix Welcome to ptSO, Thank you for your time to contribute a response. [tour]
– Icaro Martins