开发者

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 f开发者_开发问答or 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜