有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java服务对象的定义是什么?

我一直在使用PHP

但最近我被分配了一些使用Java的工作。在PHP中,我曾经做过很多单例对象,但这种模式在Java中的意义与在PHP中的意义不同

所以我想要一个实用类(一个带有静态方法的类),但是我的主管不喜欢这种类型的类,让我选择服务对象。 所以我的猜测是,服务对象只是一个带有构造函数的类,它实现了一些公共方法

我说得对吗


共 (2) 个答案

  1. # 1 楼答案

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

    关于微服务>Link服务对象定义的文章:

    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.

    我在这里理解的不是技术方面,比如将其定义为“接口”,而是它所描述的设计概念。我还理解service object只是类的一个域,就像它的职责一样。因此,如果您正在开发web应用程序,您可能会有一个服务对象SecurityService,它是SecurityController的一个组件。控制器正在调用服务以实际处理特定于安全性(域)的服务

  2. # 2 楼答案

    Domain-Driven Design将服务定义为:

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

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