
Originally Posted by
rebornspirit
Thanks for the reply
Could you explain by usng the small example below where you should put the business logic (the one that was not possible to put in the domain layer) because of dependecies):
It should be put in the domain layer, but a (bad) example of domain logic in the service is:
Code:
EmployeeService{
void fire(Employee employee){
Desk desk = employee.getDesk();
desk.clean();
employee.setStatus(FIRED);
employee.setSalary(0);
employee.setFiredDate(new Date());
employeeDao.save(employee);
}
}
So what you are saying is that I should just use the following structure:
Code:
Service ---> dao ---> database
No:
DomainLayer -> Data accesslayer -> Database
the service layer only is a very small layer that is part of your domain layer.
If you focus on the domain layer, you see:
ServiceLayer : DomainLayer
But where would you validate and add business logic, for example if we would have the simple update method
It should be part of the domain model:
Code:
class Employee{
void setSalary(int amount){
Validator validator = ... retrieve salary validator
validator.validate(amount);
_amount = amount;
}
}
But if you use a weblayer, this logic is repeated (ugly) in the weblayer. I think people should stop writing weblayers for applications, because it makes everything so complex 
We would have an update method in the dap, that just checks that the object to update is not null for example and that is has an id. But where would you put the validation and other business logic that is needed to update the object.
Example:
Code:
class Employee{
void fire(){
Desk desk = getDesk();
desk.clean();
setStatus(FIRED);
setSalary(0);
setFiredDate(new Date());
employeeDao.save(employee); //this one is questionable.
}
}
UI -> Domain -> DAO.
Because perhaps I have a wrong view on what "layered" means?
in "Patterns of Software Architecture" there is a great topic about layering.
But I'm learning
I`m also learning. I have to get a better understanding on this subject and a good discussion helps a lot.