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?
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With