Domains, DAO and Service

I need to know the difference between the type of methods (in terms of business logic) that should be inside the Domain, DAO, and Service objects of the layers.

For example, if I create a small web application for creating, editing and deleting customer data, as I understand it inside the domain-level object, I must add methods that have the properties of the Get / Set Customers object, for example (getName, getDOB, setAddress, setPhone. .. etc.).

Now what I'm trying to learn is what methods I should put in the DAO and Service layer objects.

Thank you in advance for your time and efforts.

+7
source share
2 answers

Speaking generally (not Hibernate or Spring):

The DAO level contains queries and updates to save your domain in your data warehouse (this is usually a relational database, but not required). Use interfaces to abstract your DAO from the actual data store. This does not happen often, but sometimes you want to change the data stores (or use mocks to test your logic), and the interfaces simplify this. This would have methods like save, getById, etc.

The service level usually contains your business logic and organizes the interaction between the domain level and the DAO. It will have any methods for your specific domain, such as "verifyBalance" or "calculateTotalMileage".

+8
source

DAO: wrapper methods for wrapping JPA or JDBC or SQL or noSQL or any other calls to access database systems.

Domain: business logic calls correlate with one type of object (domain object).

Service: business logic calls correlate with a group of entity types or with a group of several objects of the same type.

(I'm not sure about English, sorry .......)

This means: The service level is “greater” than the domain level, often close to the interface, often calls or uses several domain objects.

Domain objects encapsulate most of the materials for one part of the domain (therefore they are called DO)

DAO is just technical, sometimes needed, sometimes not. When real domain objects are used, often “repositories” are used to hide access to database systems or add special db functionality or something else.

front-end → service method 1 → do A type X, do B type X, List

+6
source

All Articles