4
I would like to know how to organize the CRUD (create, read, update, delete) methods of each class in Java.
An example, to better understand:
Suppose we have the classes Funcionario
, Cliente
and Produto
.
Each of these classes refers to a table in the database, that is, one for employees, one for customers and one for products.
My question is:
It is recommended/best to put the CRUD methods related to each class in themselves or whether it is better to do a class with all database operations.
For example: IncluirFuncionario()
, IncluirCliente()
and IncluirProduto()
.
It is better to put each one in his class or make another call OperacoesBD
, containing all operations for all classes?
I took the habit of putting everything in one class, because then I used and initialized only once the variable java.sql.Connection connection
in the class builder.
I think this question is very wide, I recommend you to take a good look at the Java Design Patterns, see this booklet from Caelum: https://www.caelum.com.br/apostila-java-web/
– Celso Marigo Jr