My web application is written using Spring MVC + Hibernate.
- My model is "Customer" entity POJO.
- I have got a DAO object "CustomerDAO", its method "saveCustomer(c)" contains the code interacting with Hibernate;
- Then I created a "CustomerService with a "saveCustomer(c)" method who simply pass the customer object to the dao for saving;
- Finally there are "CustomerController" and customer.jsp, who are responsible for the view layer, the jsp's form fields are bound to a Customer object on the controller side. The controller calls the service.
I saw a lot of applications follow this (best) practice but I'm wondering why I would need a service layer.
Maybe it's useful for decoupling purpose: I can show a universal facade to the controllers and inject into the service HibernateDAO, GaeDAO, MyDAO, and so on.... But I could do that without the service, too: using an interface.
I also tought: validation. I'll make my Customer validation in the service but.... it's much more convenient to validate in Spring controller.
Help me understand the concept please :)