Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the definition of a Service object?

I've been working a lot with PHP.

But recently I was assigned some work which uses Java. In PHP I used to do a lot of Singleton object but this pattern has not the same signification in Java that it has in PHP.

So I wanted to go for an utility class (a class with static method) but my chief doesn't like this kind of classes and ask me to go for services object. So my guess was that a service object is just a class with a constructor that implement some public methods...

Am I right?

like image 430
MaxouMask Avatar asked May 28 '10 10:05

MaxouMask


People also ask

What is a service object?

A service object is a Ruby object that performs a single action. It encapsulates a process in your domain or business logic. Imagine that you need to create a book instance in an imaginary library application; in a plain Rails app, you'd do the following: class BookController < ApplicationController def create Book.

What is a service object Java?

In Java, a service is defined by a set of interfaces and classes. The service contains an interface or an abstract class that defines the functionality provided by the service. There are multiple implementations for a service and they are called as service providers.

What is a service Object C#?

The Service object represents an individual service on the device and provides access to the properties, methods, and events that are exposed by the service and its content.

What are service objects in Rails?

A service object in Rails is a plain old Ruby object created for a specific business action. It usually contains code that doesn't fit in the model or view layer, e.g., actions via a third-party API like posting a tweet.


2 Answers

Domain-Driven Design defines a Service as:

A SERVICE is an operation offered as an interface that stands alone in the model, without encapsulating state... [p. 105]

Yes, it's a class with public methods, but in addition to that, it implements an interface that exposes those methods. At its core, the Service is the interface - the class that implements it is just an implementation detail.

like image 114
Mark Seemann Avatar answered Sep 21 '22 09:09

Mark Seemann


I found another definition for a service object instead that one described as an interface for concrete classes that are about to provide a certain service through that API definition set by the interface.

Article about Microservices >Link definition for service object:

3: Many object-oriented designers, including ourselves, use the term service object in the Domain-Driven Design sense for an object that carries out a significant process that isn't tied to an entity. This is a different concept to how we're using "service" in this article. Sadly the term service has both meanings and we have to live with the polyseme.

What I understand here its not the technical aspect like defining it as an "interface" but more the design concept it describes. I also understand an service object simply a domain of a class like its responsibility. So if you are developing web apps you might have a service object SecurityService which is a component of a SecurityController. The controller is calling the service to actually process security (the domain) specific services.

like image 41
xetra11 Avatar answered Sep 25 '22 09:09

xetra11