Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a DAO call DAO?

Tags:

naming

dao

I have component which needs to update the database for the customer and customer address (via JDBC). Is it appropriate to call the CustomerAddressDAO from the CustomerDAO? Or create a separate "CustomerDataManager" component which calls them separately?

like image 351
Jack BeNimble Avatar asked Jan 24 '12 14:01

Jack BeNimble


People also ask

What is the purpose of a DAO?

1 The concept of a DAO is to promote oversight and management of an entity similar to a corporation. However, the key to a DAO is the lack of central authority; the collective group of leaders and participants act as the governing body.

Is DAO a design pattern?

DAO Design Pattern is used to separate the data persistence logic in a separate layer. This way, the service remains completely in dark about how the low-level operations to access the database is done. This is known as the principle of Separation of Logic.

What is a DAO in programming?

The Data Access Object (or DAO) pattern: separates a data resource's client interface from its data access mechanisms. adapts a specific data resource's access API to a generic client interface.


1 Answers

You can do it, but that doesn't mean you should. In these cases, I like to use a Service (CustomerService in this case) that has a method call that uses both DAOs. You can define the transaction around the service method, so if one call fails, they both roll back.

The problem with DAOs that call other DAOs is you will quite quickly end up with circular references. Dependency injection becomes much more difficult.

like image 183
hvgotcodes Avatar answered Nov 02 '22 21:11

hvgotcodes