I would like to know how best to organize the CRUD (create, read, update, delete) methods of each class in Java.
An example, to get better at understanding:
Suppose we have the Funcionario
, Cliente
and Produto
classes.
Each of these classes refers to a table in the database, that is, one for the employee, the other for the customer, and the other for the products.
My question is:
It is recommended / best to put the CRUD methods related to each class in themselves, or if it is better to make a class with all database operations.
For example: IncluirFuncionario()
, IncluirCliente()
and IncluirProduto()
.
Is it better to put each one in your class or make another call OperacoesBD
, which contains all operations for all classes?
I took the custom of for everything in a class only, hence I used and initialized only once the variable java.sql.Connection connection
in the class constructor.