U
U
UNy2019-05-04 02:02:53
Java
UNy, 2019-05-04 02:02:53

What is the service layer in a Spring application doing?

I know that the Spring application is divided into different layers: Config (where our configs are), DAO (for working with the database), Model (our data, Pojo classes), Controllers (controllers) and service, which should contain business logic. In one project I saw this picture: DAO has a UserDAO class that works with the database and Service has a UserService class that has a UserDAO field and it exactly copies all UserDAO methods and simply writes UserDAO.getUsers() inside; The data then goes to the controller. Why is service needed in such applications if it simply calls methods from DAO?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-05-04
@UNy

There are two main reasons for the appearance of a "transparent service layer" in applications:

  1. Because it's accepted. The author makes a primitive application that does not need a multi-layer architecture at all , but smart uncles say that there should be layers, and he puts in ritual layers.
  2. For growth. There is nothing to put in the service layer in the MVP, but the developed business logic is expected in the next versions. It is much easier to make an empty layer and then gradually fill it in than to add it later in the working code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question