Lesson 28Exploring the Service Layer
This lesson introduces the service layer to our tiered/MVC application design. The service layer sits between the controller and the data access object (DAO) and contains the business logic for the application. We'll discuss why service layers are needed, their role in an application, and how they relate to the other application components.
THE ROLE OF THE SERVICE LAYER
So far we have the model, view, and controller components in our tiered application design. Let's review some of the MVC rules we've seen in earlier lessons.
- The model is responsible for persisting, retrieving, and ferrying data around the application.
- The controller is the orchestrator of our application: it knows what needs to be done and when it needs to be done, but it doesn't do any of the work. All work is done by other components.
- The view knows how to display what it receives, but it can't do any calculations.
This works well for CRUD applications. If all you need to do is create, read, update, and delete data and there is no business logic in your application, you are all set. But what if you need business logic? What if you need to make calculations such as tax and shipping on an order? What if you need to validate inputs such as a credit card number ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access