Layers in a Java Web Application

I am a Java web application developer.

And I found myself confused with server side layers.

I don't mean MVC (model / view / control) but dao / service levels.

Dao levels are used to bind the database.

Why Service Level?

Since we are now using the spring mvc framework, I used to handle the login to the control, including the dao call to fetch the data. Is a service level required?

+3


source to share


4 answers


There are several reasons for the service level, but for me there are a few main benefits:

  • Allows declarative transaction management in service methods, which can consist of aggregated non-transactional DAO calls.
  • Clear separation of business layer logic from simple database access.
  • Allows easier testing at higher levels by encapsulating the above into easily replaceable chunks.


Is a service level required? Of course not - but technically no layers are required; everything could be wrapped in a JSP page. It is a matter of granularity, control and separation of concerns.

+3


source


Service levels are transaction aware. They are designed to use cases and units of work. They can be useful even if your web interface is going away because they are the foundation for a Service Oriented Architecture.



I would argue that the only time I get by with a layer is read-only data access. In this case, I am more likely to dispose of the DAO than the service.

+2


source


DAO Layer - only handles database stuff, basic CRUD and some other lookups, handles DB transactions

Service layer - actually depends on the DAO layer to execute business logic, it handles business transactions

The advantage to distinguish them is that you can connect the service layer with any other interface, you will also have the ability to connect / change the DAO layer if the original store changes

Also see

+1


source


The service level is commonly used as the integration level. This prevents the DAO layer from "mixing" with functions that are not associated with it. For example:

  • Safety
  • Business logic and validation
  • External system integration

The service layer will also be used to implement various "views" of the system, mixing and matching from lower layers to create new functionality.

+1


source







All Articles