Service Layer Pattern

Sources:

Spring Boot

Presentation Layer : Controller (@Controller)

  • Merely responsible to presenting a business function (provided in Application Service Layer). Hence mostly delegation to App Service, doing data massaging and presentation-related logic.

Application Service Layer : Application Service (@Service)

  • High level speaking, it represents business use cases. Hence transaction boundary is set on the methods (as each method is a use-case, hence a unit of work). As I am against use of anemic model, real business logic should be in the domain model layer. This layer mostly make use of domain layer to compose of a meaningful use case. Mostly data transformations (depending on your design), and delegations to domain layer artifacts.

Domain Layer : Model, Domain Service (@Service), Repository (@Repository) etc

  • Business logic are in domain models, or Domain Services. Repository are the artifacts to retrieve domain models.