Java – what’s the difference between service layer and domain model layer

business-objectsdomain-modeljavaservice-layer

for example, I have a user table, to be layer-ing, I create such POJOs:

UserEntity.java
UserDao.java
UserBO.java (business object, domain model?)
UserService.java (for service layer)

what's the difference between UserBO.java and UserService.java? why we seperate it to two objects?

Best Answer

The Domain Model contains information and functionality related to what it means to be a User. It should map conceptually onto something that exists physically in the real world or a clearly defined concept in the problem space.

The Service contains information and functionality related to performing atomic units of work. It should map conceptually onto tasks that are performed on or by members of the Domain model. A single atomic task performed by clicking a button in the application generally involves many members of the Domain working together, unless you app is just a CRUD-y electronic filing cabinet.