The DAO is responsible for obtaining the business object in a storage-independent manner. For example, you can create a DAO to access the client, for example
public interface CustomerDAO { public Customer getCustomerById(Integer id) }
and then implement data access in jdbc
public class JdbcCustomerDao { public Customer getCustomerById(Integer id){ DataSource dataSource ...; Connection con = dataSource.getConnection(...); } }
or implement a CustomerDao that accesses a web service or something. CustomerDao's advantage is that the customer (the code that CustomerDao uses) is independent of nodule storage technology. This is why you should access the DAO API without dependencies between repositories. Good advice is the import statements of the CustomerDAO interface. If the CustomerDAO import statements contain something like:
import javax.sql.***
You should consider designing your API. But keep in mind that you can also introduce API dependencies with strings. For instance.
public Customer findCustomer(String sqlWhereClause){ ... }
The business object stores the data, and this is the place where you should put the domain logic in. If you are using a wealthy model approach.
See more specific examples of why the “Anemic Domain Model” is considered an anti-pattern.
source share