Let's say I have one database with two tables: companies
and employees
.
Should I create companyDAO
and employeeDAO
If I select, update, add and remove from those two tables?
Or I should create one DAO in which I'll write methods for CRUD operations for every table in the database?
Creating one DAO for the entire database doesn't scale well. The more database tables you add the larger it gets. In industry you'll almost always see a one to one DAO to table relationship. As always there are exceptions and caveats.
As the name suggest, DAO that stands for Data Access Object, is an entity to access ONE object or class. It is standard software engineering and enterprise industry (esp. in Java) best practices to have one DAO for each business entity.
If you are reusing similar behavior and data among several DAOs it is often handy to create a base DAO and extends it by other DAOs.
Also read https://en.wikipedia.org/wiki/Data_access_object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With