Building applications using a layered architecture

One of the core design aims is the separation of concerns (SoC). A good practice, irrespective of the size of an application or microservice, is to create a layered architecture.

Each layer in a layered architecture should have one concern and it should implement it well. Layering the applications also helps in simplifying unit tests. The code in each layer can be completely unit tested by mocking out the layer that follows. The following diagram shows some of the important layers in a typical microservice/web application:

The layers shown in the preceding diagram are as follows:

  • Presentation layer: In a microservice, the presentation layer is where the REST controllers reside. In a typical web application, this layer would also contain the view-related contentJSPs, templates, and static content. The presentation layer talks to the services layer.
  • Services layer: This acts a facade to the business layer. Different viewsmobile, web, and tablets—might need different kinds of data. The services layer understands their needs and provides the correct data based on the presentation layer.
  • Business layer: This is where all the business logic is. Another best practice is to put most of the business logic into the domain model. The business layer talks to the data layer to get the data and add business logic on top of it.
  • Persistence layer: This takes care of retrieving and storing data to the database. This layer typically contains the JPA mappings or the JDBC code.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset