java Service 对象的定义是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2928325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 23:29:53  来源:igfitidea点击:

What is the definition of a Service object?

javadesign-patternsterminology

提问by MaxouMask

I've been working a lot with PHP. But recently i was sent on a work wich use 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 ?

我一直在使用 PHP。但最近我被派去从事一项使用 Java 的工作。在 PHP 中,我曾经做过很多单例对象,但是这种模式在 Java 中的含义与在 PHP 中的含义不同。所以我想去一个实用程序类(一个带有静态方法的类),但我的主管不喜欢这种类,并要求我去寻找服务对象。所以我的猜测是,服务对象只是一个带有实现一些公共方法的构造函数的类......我对吗?

回答by Mark Seemann

Domain-Driven Designdefines a Service as:

领域驱动设计将服务定义为:

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

SERVICE 是作为独立于模型中的接口提供的操作,没有封装状态...... [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.

是的,它是一个具有公共方法的类,但除此之外,它还实现了一个公开这些方法的接口。在其核心,服务是接口——实现它的类只是一个实现细节。

回答by xetra11

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.

我找到了服务对象的另一个定义,而不是将其描述为即将通过接口设置的 API 定义提供特定服务的具体类的接口。

Article about Microservices>Linkdefinition 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.

3:许多面向对象的设计师,包括我们自己,在领域驱动设计意义上使用术语服务对象来表示执行与实体无关的重要过程的对象。这与我们在本文中使用“服务”的方式不同。可悲的是,服务一词有两种含义,我们不得不忍受多义词。

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 objectsimply a domain of a class like its responsibility. So if you are developing web apps you might have a service object SecurityServicewhich is a component of a SecurityController. The controller is calling the service to actually process security (the domain) specific services.

我在这里理解的不是将其定义为“接口”之类的技术方面,而是它所描述的设计概念。我也理解一个service object简单的类的域,比如它的职责。因此,如果您正在开发 Web 应用程序,您可能有一个服务对象SecurityService,它是SecurityController. 控制器调用服务来实际处理安全(域)特定服务。