liveBook · Manning

Service

As explained in Spring Start Here, Second Edition

A service is an application component responsible for implementing one or more use cases.

A service is an application component responsible for implementing a use case. It coordinates the work without taking on every responsibility itself. section 4.1.3

Publishing a comment

CommentService implements the publish-comment use case: it delegates storing the comment to a repository and sending an email notification to a proxy. Interfaces keep the service decoupled from those implementations. section 4.1.3

In Spring, @Service marks a component’s responsibility explicitly; Spring creates an instance and adds it to its context. Use @Repository to mark a component responsible for data persistence. section 4.3

Figure 4.6 The CommentService object depends on the abstractions provided by CommentRepository and CommentNotificationProxy interfaces. The classes DBCommentRepository and EmailCommentNotificationProxy further implement these interfaces. This design decouples the implementation of the “publish comment” use case from its dependencies and makes the application easier to change for future developments.

The diagram shows how interfaces let the service depend on abstractions rather than specific implementations. section 4.1.3

How Spring Start Here, Second Edition covers it

How deep it goes
Explains a service through a worked comment-publishing design and Spring’s @Service stereotype, without elaborating service internals.
Examples
Uses CommentService to publish a comment by storing it and sending an email notification.
What it assumes
Starts with plain Java objects and a comment use case before introducing Spring stereotype annotations.
What you can do after
Build a use-case service that delegates through interfaces to persistence and notification components.
How it connects
Connects services to repositories, proxies, interfaces, dependency injection, and Spring component stereotypes.

Also explained in

Compare how 4 books explain service →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.