Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

layers in java web application [closed]

I am a java web application developer.

And I found I am coufused with the layers in the server side.

I do not mean the MVC(model/view/control) but the dao/service layers.

Dao layers is used to conntect the database.

Why the service layer?

Since we use the spring mvc framework now,I used to process the login in the control including call the dao to fetch data. Is the service layer necessary?

like image 656
hguser Avatar asked Feb 21 '23 02:02

hguser


1 Answers

There are several reasons for the service layer, but for me there are a few primary advantages:

  1. Allows declarative transaction control on service methods, which may consist of aggregated non-transactional DAO calls.
  2. Clear separation of business layer logic from mere DB access.
  3. Allows easier testing at higher levels by encapsulating the above into easily-replaceable chunks.

Is the service layer necessary? Of course not--but technically no layers are necessary; everything could be wrapped up in a JSP page. It's a matter of granularity, control, and separation of concerns.

like image 154
Dave Newton Avatar answered Mar 04 '23 06:03

Dave Newton